Rails: select unique values from a column

I already have a working solution, but I would really like to know why this doesn’t work:

ratings = Model.select(:rating).uniq
ratings.each { |r| puts r.rating }

It selects, but don’t print unique values, it prints all values, including the duplicates. And it’s in the documentation: http://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields

14 Answers
14

Leave a Comment