2011-06-29 70 views
0

专门的admin/countries_controller正在正确使用所有操作(index,...),除了创建记录。这里从父目录控制器定期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操作被路由到管理/国家

的routes.rb:

resources :countries 

    namespace :admin do 
    resources :countries 
    end 

耙路线:

 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

你是如何构建在你的视图中启动POST请求的url的? – drummondj

+0

'<%= link_to'New Country',new_admin_country_path%>'会产生标准的scaffold form helper,包含'<%= form_for(@country)do | f | %>'和'<%= f.submit%>' – David

回答

1

form_for需要过于命名空间:

<%= form_for [:admin, @country] do |f| %> 
    ... 
<% end %> 

当你传递@countryform_for它不会知道你想要这种形式去什么命名空间,所以它会默认为只是标准POST /countries URL。

+0

不错,谢谢瑞恩! – David

相关问题