0

通过以下路线,我遇到了冲突问题。似乎两者不能同时存在。如何在不冲突的情况下同时指定两者?谢谢。

 resources :colleges do
    resources :departments
 end

 resources :departments do
    resources :professors
 end   

路径new_college_department_path(@college)产生 url colleges/1/departments/new,这又导致以下错误。我不确定为什么要列出控制器教授,因为它甚至不是路线的一部分!

 Routing Error

No route matches {:controller=>"professors", :format=>nil, :request_id=>#<department_id: nil, text: nil, goal: nil, accept: nil, post_url: nil, created_at: nil, updated_at: nil, u_id: nil, b_id: 1, active: nil>}

路线:

blog_requests GET    /blogs/:blog_id/requests(.:format)                  requests#index
                       POST   /blogs/:blog_id/requests(.:format)                  requests#create
      new_blog_request GET    /blogs/:blog_id/requests/new(.:format)              requests#new
     edit_blog_request GET    /blogs/:blog_id/requests/:id/edit(.:format)         requests#edit
          blog_request GET    /blogs/:blog_id/requests/:id(.:format)              requests#show
                       PUT    /blogs/:blog_id/requests/:id(.:format)              requests#update
                       DELETE /blogs/:blog_id/requests/:id(.:format)              requests#destroy
                 blogs GET    /blogs(.:format)                                    blogs#index
                       POST   /blogs(.:format)                                    blogs#create
              new_blog GET    /blogs/new(.:format)                                blogs#new
             edit_blog GET    /blogs/:id/edit(.:format)                           blogs#edit
                  blog GET    /blogs/:id(.:format)                                blogs#show
                       PUT    /blogs/:id(.:format)                                blogs#update
                       DELETE /blogs/:id(.:format)                                blogs#destroy
    request_supporters GET    /requests/:request_id/supporters(.:format)          supporters#index
                       POST   /requests/:request_id/supporters(.:format)          supporters#create
 new_request_supporter GET    /requests/:request_id/supporters/new(.:format)      supporters#new
edit_request_supporter GET    /requests/:request_id/supporters/:id/edit(.:format) supporters#edit
     request_supporter GET    /requests/:request_id/supporters/:id(.:format)      supporters#show
                       PUT    /requests/:request_id/supporters/:id(.:format)      supporters#update
                       DELETE /requests/:request_id/supporters/:id(.:format)      supporters#destroy
              requests GET    /requests(.:format)                                 requests#index
                       POST   /requests(.:format)                                 requests#create
           new_request GET    /requests/new(.:format)                             requests#new
          edit_request GET    /requests/:id/edit(.:format)                        requests#edit
               request GET    /requests/:id(.:format)                             requests#show
                       PUT    /requests/:id(.:format)                             requests#update
                       DELETE /requests/:id(.:format)                             requests#destroy
                       GET    /requests(.:format)                                 requests#index
                       POST   /requests(.:format)                                 requests#create
                       GET    /requests/new(.:format)                             requests#new
                       GET    /requests/:id/edit(.:format)                        requests#edit
                       GET    /requests/:id(.:format)                             requests#show
                       PUT    /requests/:id(.:format)                             requests#update
                       DELETE /requests/:id(.:format)                             requests#destroy
            supporters GET    /supporters(.:format)                               supporters#index
                       POST   /supporters(.:format)                               supporters#create
         new_supporter GET    /supporters/new(.:format)                           supporters#new
        edit_supporter GET    /supporters/:id/edit(.:format)                      supporters#edit
             supporter GET    /supporters/:id(.:format)                           supporters#show
                       PUT    /supporters/:id(.:format)                           supporters#update
                       DELETE /supporters/:id(.:format)                           supporters#destroy
                 users GET    /users(.:format)                                    users#index
                       POST   /users(.:format)                                    users#create
              new_user GET    /users/new(.:format)                                users#new
             edit_user GET    /users/:id/edit(.:format)                           users#edit
                  user GET    /users/:id(.:format)                                users#show
                       PUT    /users/:id(.:format)                                users#update
                       DELETE /users/:id(.:format)                              
4

2 回答 2

1

If professorsis children of departmentsand departmentsif children of collegesyou 可以定义如下:

 resources :colleges do
    resources :departments do
      resources :professors
    end
 end

因此,您的路径将是:

colleges/1/departments/1/professors/1
于 2012-06-25T08:51:32.600 回答
1

错误出现在 form_for 中。路线还可以。

于 2012-06-25T12:54:14.583 回答