scoped_search
scoped_search copied to clipboard
Use function for complete value
It would be nice to pass a function that returns a hash to complete value to be used for autocomplete
for instance
scoped_search :on => :xyz, :complete_value => :create_hash
def create_hash
....
my_new_hash
end
Can you describe your use case for this?
sure, so I am doing this on a two-column version number, one is major and the other minor. so version 3.1 is stored in as major => 3 and minor => 1. This proved difficult to add autocomplete as I am using scoped search on the major column with a custom query. The autocomplete currently will return major versions only. So I would write a custom function to make a hash of all of the major and minor versions as a float and use that in complete value.
I realize this seems like a particular case, but I can imagine other situations that this would be useful, and increases the flexibility of the gem's functionality, especially while using custom search queries.
while inefficient, many times I've found myself adding another db column in favour of search usability, maybe you could simply have a label attribute that you can search on.
@ohadlevy this is a good idea, thanks :)