In my rails app have a partial that contains a form shared between the new and edit action:
<%= form_for @customer do |f| %>
....
<% end %>
These action are of a controller (called customers) namespaced (cal开发者_StackOverflowled admin), if try to run the code show the error when execute form_for:
undefined method `customer_path'
Have resolved this using:
<%= form_for :customer, @customer do |f| %>
.... <% end %>
Now the form is generated with correct url when is called by new action but when generated by edit the form url is "/admin/customers/1/edit" instead of update. If submit the form show the error:
No route matches "/admin/customers/1/edit"
but in routes.rb have:
namespace :admin do
resources :customers
end
and rake:routes show all the REST urls:
admin_customers GET /admin/customers(.:format) {:action=>"index", :controller=>"admin/customers"} POST /admin/customers(.:format) {:action=>"create", :controller=>"admin/customers"} new_admin_customer GET /admin/customers/new(.:format) {:action=>"new", :controller=>"admin/customers"} edit_admin_customer GET/admin/customers/:id/edit(.:format){:action=>"edit",:controller=>"admin/customers"} admin_customer GET /admin/customers/:id(.:format) {:action=>"show",:controller=>"admin/customers"} PUT /admin/customers/:id(.:format) {:action=>"update", :controller=>"admin/customers"} DELETE /admin/customers/:id(.:format) {:action=>"destroy",:controller=>"admin/customers"}
Any idea?
Try this
<%= form_for [:admin, @customer] do |f| %>
精彩评论