嵌套资源和设置我的控制器,rails 3

时间:2011-08-17 15:26:45

标签: ruby-on-rails ruby-on-rails-3 routes

所以我试图嵌套我的资源,以便成员有图像,这是我的路线

resources :members, :except => [:new, :create] do
    resources :tattoos
end

在我耙路线时给了我这些路径:

       member_tattoos GET    /members/:member_id/tattoos(.:format)          {:action=>"index", :controller=>"tattoos"}
                      POST   /members/:member_id/tattoos(.:format)          {:action=>"create", :controller=>"tattoos"}
    new_member_tattoo GET    /members/:member_id/tattoos/new(.:format)      {:action=>"new", :controller=>"tattoos"}
   edit_member_tattoo GET    /members/:member_id/tattoos/:id/edit(.:format) {:action=>"edit", :controller=>"tattoos"}
        member_tattoo GET    /members/:member_id/tattoos/:id(.:format)      {:action=>"show", :controller=>"tattoos"}
                      PUT    /members/:member_id/tattoos/:id(.:format)      {:action=>"update", :controller=>"tattoos"}
                      DELETE /members/:member_id/tattoos/:id(.:format)      {:action=>"destroy", :controller=>"tattoos"}
              members GET    /members(.:format)                             {:action=>"index", :controller=>"members"}
          edit_member GET    /members/:id/edit(.:format)                    {:action=>"edit", :controller=>"members"}
               member GET    /members/:id(.:format)                         {:action=>"show", :controller=>"members"}
                      PUT    /members/:id(.:format)                         {:action=>"update", :controller=>"members"}
                      DELETE /members/:id(.:format)                         {:action=>"destroy", :controller=>"members"}

但是如果我使用这些link_to的

<%= link_to "Manage tattoos", member_tattoos_path %>
<br />
<%#= link_to "Upload new tattoo", new_member_tattoo_path %>

我收到错误:

No route matches {:controller=>"tattoos"}

甚至tattoos_controller.rb确实存在。是什么给了什么?

我是否需要以任何特定方式设置我的tattoo_controller?我问,因为现在我的链接正确,我无法提交任何新记录,我得到一个错误:

Started POST "/members/1/tattoos/new" for 127.0.0.1 at 2011-08-17 13:11:40 -0400

ActionController::RoutingError (No route matches "/members/1/tattoos/new"):

1 个答案:

答案 0 :(得分:1)

您需要在使用路径助手时将:member_id放入其中:

member_tattoos_path(:member_id => @member.id)