Closed acesuares closed 3 years ago
I now tried something different. On the words_controller, I have
autocomplete :word, :name, full: false, limit: 12
On the memory_games_controller, I have
autocomplete :word, :name, full: false, limit: 12, scopes: [:has_pictures]
In routes.rb, I added
resources :memory_games do
get :"autocomplete_word_name", :on => :collection
end
rake:routes give both routes:
autocomplete_word_name_words GET /words/autocomplete_word_name(.:format) words#autocomplete_word_name
autocomplete_word_name_memory_games GET /memory_games/autocomplete_word_name(.:format) memory_games#autocomplete_word_name
In the view, I can use:
<%= autocomplete_field_tag :add_word, '', send("autocomplete_word_name_words_path"), :placeholder => 'buska palabra...', :id => 'input_search' %>
and this works, but of course it is showing all words, not just the one with pictures. When I change it to:
<%= autocomplete_field_tag :add_word, '', send("autocomplete_word_name_memory_games_path"), :placeholder => 'buska palabra...', :id => 'input_search' %>
I get the error:
"GET /memory_games/autocomplete_word_name?term=ala HTTP/1.1" 404 15077
I'm lost.
Well, I moved the route up, above the one that declares /words/autocomplete_word_name, and now it works
autocomplete_word_name_memory_games GET /memory_games/autocomplete_word_name(.:format) memory_games#autocomplete_word_name
autocomplete_word_name_words GET /words/autocomplete_word_name(.:format) words#autocomplete_word_name
I am still lost, but hey! it works.
I have a words_controller with:
I added a second autocomplete:
I also added a route for the second autocomplete:
I added a method in the controller:
The following works now (it generates JSON):
But this doesn't work:
If I remove the route for words_with_pictures
then it still doesn't work, but if I reverse the order of the autocomplete statements in the controller:
then this works:
Obviously, the other one doesn't work since there is no route for it anymore.
My questions: