Rails: select unique values from a column
Model.select(:rating) The result of this is a collection of Model objects. Not plain ratings. And from uniq‘s point of view, they are completely different. You can use this: Model.select(:rating).map(&:rating).uniq or this (most efficient): Model.uniq.pluck(:rating) Rails 5+ Model.distinct.pluck(:rating) Update Apparently, as of rails 5.0.0.1, it works only on “top level” queries, like above. Doesn’t work on … Read more