Is it possible to select DISTINCT values using Rails3 JQuery autocomplete gem?
It is much better and simpler to use scopes.
In your model:
scope :uniquely_named, group(:name)
In your controller:
autocomplete :user, :name, :scopes => [:uniquely_named]
This solution allows more complex filtering to be easily applied:
model:
scope :uniquely_named, group(:name)
scope :online, where(:online => true)
controller:
autocomplete :user, :name, :scopes => [:uniquely_named, :online]
source
Doesn't appear to - but - the 'autocomplete' macro is really just defining an action in your controller. I'd forego using 'autocomplete' in my controller and just implement the action myself...
def autocomplete_for_user_name
User.select('distinct name')
end
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With