Daily Archives: September 11, 2012

You are browsing the site archives by date.

Select a single column with active record

I have an ‘Image’ model and I needed to select only the ‘id’ column as an array.

ids = Image.pluck(:id)

You can easily combine this with a where clause.

ids = Image.where(field: 'value').pluck(:id)

Check the official documentation.