Ruby on Rails的3条嵌套的路线:错误的行动路线
问题描述:
我有两个模式:团队和项目Ruby on Rails的3条嵌套的路线:错误的行动路线
的routes.rb
resources :teams do
resource :projects
end
而且两个问题!
1-根据http://guides.rubyonrails.org/routing.html,我期望得到team /:team_id/projects /:id路径。然而,这种情况并非如此。
耙路线
team_projects POST /teams/:team_id/projects(.:format) projects#create
new_team_projects GET /teams/:team_id/projects/new(.:format) projects#new
edit_team_projects GET /teams/:team_id/projects/edit(.:format) projects#edit
GET /teams/:team_id/projects(.:format) projects#show
PUT /teams/:team_id/projects(.:format) projects#update
DELETE /teams/:team_id/projects(.:format) projects#destroy
,所以我不得不名路线得到它的工作
match 'teams/:team_id/projects/:id' => 'projects#show', :via => [:get], :as => :show_project
所以如何能利用轨辅助方法,而不是对其进行命名的?
2-在项目表演动作来看,调试器抛出这些参数对我来说:
action: show
controller: projects
team_id: '1'
这是罚款。但是当我点击“new_team_projects_path” URL,它重定向我相同的观点和调试器抛出这些参数:
controller: projects
action: show
team_id: '1'
id: new
它不重定向我到新的行动,但它采取了“新”作为ID!为什么?
答
-
您需要使用
resources :teams do resources :projects end
注意多!
resource
产生没有身份证的单一路线。 与第一次修复不再相关。
严重??!我找了几个小时的解决方案。非常感谢。 – PeaceDefener 2012-07-21 03:08:41
嗯,这是在指南;)但我知道那种感觉。 – Femaref 2012-07-21 12:15:50
这导致我/ magazine /:id/ads将路由到#show而不是#index的问题 – troutinator 2014-12-12 19:30:15