xmnucg
Last Updated: February 25, 2016
·
321
· sebastialonso
9b0f7bbf22d65fa2bd23496973c0ba80

Getting a single attribute from an array of associations in Rails

There's a one liner for this, I can't believe how simple it is, and how much time passed before I realized I could do this.

users = User.limit(10)

You want to grab the :name or :some_other attribute

users.pluck(:name)
# => ['Alice', 'Bob',...., 'Eve']

Never stop being a noob