我有两个模型:团队和项目
路线.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
那么如何利用 rails 辅助方法而不是命名它们呢?
2- 在项目显示操作视图中,调试器为我抛出这些参数:
action: show
controller: projects
team_id: '1'
这很好。但是当我点击“new_team_projects_path”网址时,它会将我重定向到同一个视图,并且调试器会抛出这些参数:
controller: projects
action: show
team_id: '1'
id: new
它不会将我重定向到新操作,而是将“新”作为 ID!为什么?