views:

62

answers:

2

I have a resource :products in a namespace :shop, like this:

namespace :shop do
  resources :products
  root :to => 'products#index'
end

When running rake routes it outputs the following:

edit_shop_product GET    /shop/products/:id/edit(.:format) {:action=>"edit", :controller=>"shop/products"}

But when I use the edit_shop_product_path in a partial view, like this:

<%= button_to "Edit", edit_shop_product_path(product) %>

I get an ActionController Exception: No route matches "/shop/products/1/edit"

What am I missing?

A: 
  1. Create a directory named shop under the controllers/ directory
  2. Create a ruby file named products_controller.rb under the shop directory
  3. Name the controller class Shop::ProductsController < BaseController
jpartogi
All those are in place already. The index, new and create actions work as expected. It's just the edit action that fails with this error when rendering the view.Thanks for the reply, though!
harald
That's weird. It should work.
jpartogi
That's what I thought too :)= I'll see if I get some more time to debug it this weekend.
harald
A: 

Ok, I found the answer myself in the end. The problem is the button_to method which defaults to generating a POST http request. By changing this to a GET like this:

<%= button_to "Edit", edit_shop_product_path(product), :method => :get %>

Or by using the link_to method it works as advertised.

harald