I have a search input box for them to insert ‘tags’, and it autocompletes the box. This is going to be an ajax request to Tag.all.
Unfortunately, i have resource :tags in my routes, and i’m using ALL the rest actions for other things in tags_controller.rb (:index, :get, :new, :create, :update, :destroy, etc).
Would I make an entirely new controller or how would i go about doing this. Or should I add something else to the tags_controller just for ajax. I know how to do it many other ways I just want to follow the best rails conventions.
Also how do I go about adding it so it returns json in the appropriate ‘rails way’?
Thanks!
Rails normally would dictate that you use the index action (as you are requesting all the resourceS) with a respond_to block, and respond differently based on whether the call is asking for html or JSON. Here’s a link to the Rails guides that explains it in a bit more depth.
http://guides.rubyonrails.org/action_controller_overview.html#rendering-xml-and-json-data