Getting attribute directly from rails Class.find (: all) array of objects

I know that Person.find (: all) returns an array of Person objects, but somehow I can just get the name property for all people in the Person table?

Sort of

        Person.find(:all).names
+5
source share
1 answer

Use: select to get only certain attributes.

Person.all(:select => :name)

Provides you object objects that have only the name attribute. Then you can match / assemble this attribute to get an array of names.

+6
source

All Articles