Getting id in an array

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 ?

David N. 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”)

On Tue, Jul 29, 2008 at 4:36 AM, David N.
[email protected] 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}

David N. 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)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs