lundi 10 août 2015

Rails3 Autocomplete Gem - Two Different Autocompletes on Same ClassName and Method

I am successfully using the ":scopes =>" option of this gem to return a subset of the rows of the table. Now I want to create a nearly identical autocomplete, on the same ClassName and Method, with a different scope, for a different view.

The problem is, the first two arguments of autocomplete in the controller are ClassName and Method, and those also create the functional name of the autocomplete function, as it is used in the view and route. Therefore, both of my autocompletes would have the same name.

Is there a workaround I can use to assign a different name to each of the similar autocompletes?

Example code:

autocomplete :my_class_name, :my_method, :display_value => :my_formatting_method, 
:extra_data => [:id], :scopes => [:active_and_special]

def active_and_special
    where("active = ?", true).
    where("special = ?", true).
    order("name  ASC")
end

Then the again for the 2nd one, with the same class-name and method, but a different scope.

Aucun commentaire:

Enregistrer un commentaire