Hi, I''m begining with rails I need to get an array of all id of a table. name of my model is ContentGroup so I tried ContentGroup.find(:all, :order=>"ASC") but I have an array of objet and I only need the ids. How can I do to get only id fields ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Jul 29, 2008 at 4:36 AM, David Nguyen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > I''m begining with rails I need to get an array of all id of a table. > > name of my model is ContentGroup so I tried ContentGroup.find(:all, > :order=>"ASC") > but I have an array of objet and I only need the ids. > > How can I do to get only id fields ?ContentGroup.find(:all, :order=>"ASC").collect {|cg| cg.id}> Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Nguyen wrote:> Hi, > I''m begining with rails I need to get an array of all id of a table. > > name of my model is ContentGroup so I tried ContentGroup.find(:all, > :order=>"ASC") > but I have an array of objet and I only need the ids. > > How can I do to get only id fields ?Hi Try this @user=ContentGroup.find(:all,:select=>"id",:order=>"id asc") -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David Nguyen wrote:> Hi, > I''m begining with rails I need to get an array of all id of a table. > > name of my model is ContentGroup so I tried ContentGroup.find(:all, > :order=>"ASC") > but I have an array of objet and I only need the ids. > > How can I do to get only id fields ?ContentGroup.find(:all, :select => ''id'').map(&:id) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---