How do I specify an action on a resource in a namespace in rails 3?
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"
Wha开发者_StackOverflow社区t am I missing?
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.
- Create a directory named shop under the
controllers/
directory - Create a ruby file named
products_controller.rb
under the shop directory - Name the controller
class Shop::ProductsController < BaseController
精彩评论