I’m trying to edit a form, the route is controller/id/action for edit so for example
people/124321/edit
I’m trying to make this form submit to the update action using this code:
<% form_for :probe, @probe, :action => "update" do |f| %>
...
...
...
<%= submit_tag 'Submit' %>
<% end %>
When I click submit, it gives me an error stating
Unknown Action.
No action responded to (id).
Edit
The only thing in my routes specified for probes is map.resources :probes
RoR just did the people/124321/edit by itself when I generated the controller.
Rake routes shows this
probes GET /probes(.:format) {:controller=>"probes", :action=>"index"}
POST /probes(.:format) {:controller=>"probes", :action=>"create"}
new_probe GET /probes/new(.:format) {:controller=>"probes", :action=>"new"}
edit_probe GET /probes/:id/edit(.:format) {:controller=>"probes",action=>"edit"}
GET /probes/:id(.:format) {:controller=>"probes", :action=>"show"}
PUT /probes/:id(.:format) {:controller=>"probes", :action=>"update"}
DELETE /probes/:id(.:format) {:controller=>"probes", :action=>"destroy"}
Edit 2 Probe Controller
def edit
@probe = Probe.find(params[:id])
end
def update
@probe = Probe.find(params[:id])
debugger
if @probe.update_attributes(params[:probe])
flash[:notice] = "Successfully updated probe."
redirect_to probes_path
else
render :action => 'edit'
end
end
It’s hard to say exactly since you have posted very little supporting details for your question, but my guess is that your routes file is set up such that the precedence of something matching
:controller/:action/:idcomes before the route you’re aiming for,:controller/:id/:action.Routes are evaluated top-down, first match wins.
I’ll echo John’s answer, too. You shouldn’t need to specify
:action => 'update', and in fact these days I usually extract the form out of bothnew.html.erbandedit.html.erbinto a partial_form.html.erb.form_forwill figure out if the object is a new record and POST to either thecreateorupdateaction, as appropriate.I have seen some situations in the past where route changes reloaded in development mode confuse the routing code, which is usually fixed by restarting the server.
rake routesis also a good debugging tool. Check the page source to see what Rails has used for the form’sactionattribute, then scan down the output ofrake routesto see where the request will end up.