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.
Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.
The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.
Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.
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.
URLs don't map directly to ApplicationController
- only subclasses of it.
You need to move the call to autocomplete
into another controller. The location of the form shouldn't make a difference, as long as you're passing the correct path when you define your text_field
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With