I have a form to update an attribute of a model – I don’t want it to go to the standard update action I want it to go to a different action.
<% for car in @cars %>
<%= form_for car, :url => { :action => "custom_action/#{car.id}" } do |f| -%>
This is giving the following error –
No route matches {:action=>"custom_action/1", :controller=>"cars"}
However if I visit the url – custom_action/1 – I don’t get the routing error.
Any idea why I can’t do this?
In addition to what Frederick Cheung said about GET vs POST vs PUT, I think your code might be wrong in general.
To do exactly what you want, try:
I don’t think this is a good idea, and will probably cause you pain. I suggest taking a look at the Ruby on Rails Routing Guide, to understand how to do this properly. (Routing is a topic where I always have to consult the manual.)
With correct routes your code should look something like this:
Which will be easier to change in the future if/when you refactor your app.