除了创建记录之外,专用的admin / countries_controller正在用于所有操作(索引,...)。这里来自父控制器目录的常规countries_controller是活动的:
Started POST "/countries" for 127.0.0.1 at 2011-06-29 23:26:38 +0200
Processing by CountriesController#create as HTML
将POST操作路由到 admin / countries 缺少什么?
routes.rb中:
resources :countries
namespace :admin do
resources :countries
end
rake routes:
countries GET /countries(.:format) {:action=>"index", :controller=>"countries"}
POST /countries(.:format) {:action=>"create", :controller=>"countries"}
new_country GET /countries/new(.:format) {:action=>"new", :controller=>"countries"}
admin_countries GET /admin/countries(.:format) {:action=>"index", :controller=>"admin/countries"}
POST /admin/countries(.:format) {:action=>"create", :controller=>"admin/countries"}
new_admin_country GET /admin/countries/new(.:format) {:action=>"new", :controller=>"admin/countries"}
类似的问题在这里没有答案: Rails help with building Admin area - Routing problem
答案 0 :(得分:1)
您的form_for
也需要命名空间:
<%= form_for [:admin, @country] do |f| %>
...
<% end %>
当您将@country
传递给form_for
时,它不会知道您希望此表单转到哪个命名空间,因此它将默认为标准POST /countries
网址。