Using acts-as-taggable-on and rails4-autocomplete to autocomplete tags. Here is my code.
routes.rb
get 'tags/:tag', to: 'posts#index', as: :tag
resources :posts do
get :autocomplete_tag_name, :on => :collection
end
posts_controller.rb
autocomplete :tag, :name
application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
_form.html.haml
= f.input :tag_list, :url => autocomplete_tag_name_posts_path, :as => :autocomplete
When I start typing, I can see the request to the server but return (404) Not Found as
http://localhost:3000/posts/autocomplete_tag_name?term=rails
Firefox DevTool Network
ActiveRecord::RecordNotFound at /posts/autocomplete_tag_name
============================================================
> Couldn't find Post with 'id'=autocomplete_tag_name
app/controllers/posts_controller.rb, line 133
---------------------------------------------
``` ruby
128 end
129
130 private
131 # Use callbacks to share common setup or constraints between actions.
132 def set_post
> 133 @post = Post.find(params[:id])
134 end
135
136 # Never trust parameters from the scary internet, only allow the white list through.
137 def post_params
138 params.require(:post).permit(:title, :body, :image, :tag_list)
It couldn't find a post with id autocomplete_tag_name
which it shouldn't be like this.
If I hard coded the request to
http://localhost:3000/tags/autocomplete_tag_name?term=rails
It returns 200 (ok)