1

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 (called 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?

1 Answer 1

3

Try this

<%= form_for [:admin, @customer] do |f| %>
Sign up to request clarification or add additional context in comments.

3 Comments

the generated form action is "/admin/customers/1", if submit return to index page without any change to record.
it is correct action, actually. And what did you expect? If nothing changes - there is a problem in your controller code
Ops, sorry, a logic error in update method, now works. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.