rails-3jquery-automcomplete path helper not returning correct path in rails 3.1.1
I have a model:
class EvidenceType < ActiveRecord::Base
has_many :evidences
attr_accessible :name
end
A controller:
class EvidencesController < ApplicationController
autocomplete :evidence_type, :name
In my view:
<%= form_tag do %>
<%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>
<% end %>
In Routes.rb:
resources :evidences do
get :autocomplete_evidence_type_name, :on => :collection
end
rake routes gives me:
autocomplete_evidence_type_name_evidences GET /evidences/autocomplete_evidence_type_name(.:format) {:action=>"autocomplete_evidence_type_name", :controller=>"evidences"}
When i start typing in the autocomplete field i see a request int the rails log:
Started GET "/autocomplete/evidences/autocomplete_evidence_type_name?term=co" for 127.0.0.1 at Tue Oct 11 17:45:57 +0100 2011
ActionController::RoutingError (No route matches [GET] "/autocomplete/evidences/autocomplete_evidence_type_name"):
If I manually go to http://localhost:3000/evidences/autocomplete_evidence_type_name?term=xx t开发者_如何学Chen i get the desired snippet returned, which leads me to believe everything seems to be glued together properly with jquery.
I figure I either need to add an extra 'autocomplete' to my route (seems hackish?) or that my autocomplete_evidence_type_name_evidences_path helper needs to drop the /autocomplete off of the front.
However, having said this, I suspect that it might be me that is doing something wrong? Any ideas?
On this line:
<%= autocomplete_field_tag 'evidence', '', :autocomplete => autocomplete_evidence_type_name_evidences_path %>
You don't need :autocomplete =>
. That is what's adding the extra /autocomplete
to the URL. Just use:
<%= autocomplete_field_tag 'evidence', '', autocomplete_evidence_type_name_evidences_path %>
I used this gem for a while and unless something has changed in the past few months, that should fix it for you.
精彩评论