How do you route an action to the application controller in Rails 3?

Hard-Boiled Wonderland picture Hard-Boiled Wonderland · Jan 24, 2011 · Viewed 17.7k times · Source

I am using the gem rails3-jquery-autocomplete and had no problems with it, however I have now moved my autocomplete form into the application template and therefore the ajax calls are now being dealt by the application controller, so my routes have changed from:

home/autocomplete_category_name

and now need to have the home removed and the path from:

home_autocomplete_category_name_path

to:

autocomplete_category_name_path

Anybody got any ideas? Still learning the ins and outs of Rails so this is a dead end for me right now.

Thanks.

Answer

Pavling picture Pavling · Mar 21, 2013

Old post, but the accepted answer is wrong. Though the spirit of it is right - you should probably move your method to a more appropriate controller; but if you insist on having the method in application_controller.rb

# routes.rb
match '/some_route', to: 'application#some_route', as: :some_route

...will route to the 'some_route' method in application_controller.rb.