Topic: distinct select
I am using the Rails 3 Jquery Autocomplete plugin. The problem with the plugin is it does not return distinct values. I googled and found the following solution: http://stackoverflow.com/questions/4869 -in-rails3
This solution suggested overriding the get_items function, which can be found at: https://github.com/crowdint/rails3-jque 144d#L1R84
This works if you only are applying autocomplete for one field. But what if you have autocomplete for multiple fields? For example, say you want to apply autocomplete to both title and author. How would you rewrite the following so it could serve both?
PostController
----------------------------------
autocomplete :post, :title, :full => true
autocomplete :post, :author, :full => true
def get_items(parameters)
Post.select("distinct title").where(["title LIKE ?", "#{parameters[:term]}%"])
end
----------------------------------
Currently that only works for the title field. It does not work for the author field.