Reputation: 5345
I'm am trying to implement JQuery autocomplete in my Rails 3 app. Here are the relevant code:
<%= event_form.text_field :evaluator_id, :class => "form-control" %>
$("#event_evaluator_id").autocomplete
source: "presenters_path"
match "events/presenters/" => "events#presenter_tokens", :as => 'presenters'
def presenter_tokens
if(@presenter_tokens.nil?)
@presenter_tokens = self.presenter_connections.order(:position).pluck(:learner_id).join(',')
end
@presenter_tokens
end
The error I am getting in the JS console when I start typing in the text field is:
GET http://localhost/events/2119/presenters_path?term=ma 404 (Not Found)
Upvotes: 0
Views: 39
Reputation: 1954
Your problem is in the javascript. Javascript does not have access to the helper methods.
$("#event_evaluator_id").autocomplete
source: "presenters_path"
Here you are telling javascript that source is literally "presenters_path", thats what you see in the console as being appended to the path. Change the source to actual path /events/presenters/
and it should get to the correct route.
Upvotes: 2