Tag Archives: Single Column

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.