Ruby-on-Rails: Selecting Distinct Values from the Model
The Docs: Clearly State That: Query = Client. Select(: Name). Distinct # => Returns Unique Names However, When I Try That in My Controller, I Get the Following...
The docs:
Clearly state that:
query = Client.select(:name).distinct
# => Returns unique names
However, when I try that in my controller, I get the following error:
undefined method `distinct' for #<ActiveRecord::Relation:0xb2f6f2cc>
To be clear, I want the distinct names, like ['George', 'Brandon'], not the clients actual records. Is there something that I am missing?
4 Answers
Rails 2
If you are still on rails 2 you will need to use:
Client.select('distinct(name)')