views:

492

answers:

2

I have a Rails app with a "Route" resource, and a "Route" controller (not to be confused w/ Rails routes). I've set it up so that the site admins (and only the admins) can manage the "Route" resource through the "Route" controller, while regular users manage their routes with a "Myroute" controller. I want both controllers to utilize RESTful routing, but I'm having trouble with the form_for function in the "edit" view for the "Myroute" controller.

My form tag for the "edit" view of the "Myroute" controller is currently:

<% form_for @route, :url => { :id => @route.id }, :html => { :method => :put } do |f| %>

Which resolves to the following:

<form action="/myroutes/44/edit" class="edit_route" id="edit_route_44" method="post">

This is not correct, since the form's action should go to the "create" method, and the "edit" method only handles GET requests. From what I can tell by looking at the HTML generated from the "Route" views, the the form should make a PUT request to "/myroutes/44"

How do I write a form_for tag so that it uses RESTful routing to make a PUT reqest to the "update" method of a controller that is not the same as the model?

+3  A: 

How about:

<% form_for @route, :url => {:action => 'update', :id => @route.id },
 :html => { :method => :put } do |f| %>
JRL
A: 

turns out this also works:

  <% form_for @route, :url => myroute_path(@route) do |f| %>
aaronstacy