在Rails 4.2.6中,我正在创建像这样的嵌套资源
routes.rb中:
resources :analysis, param: :project_id do
resources :configuration
end
resources :decision, param: :project_id do
resources :configuration
end
当我在分析或决策控制器中时,它工作正常。但是,当我在配置控制器中时,我会收到参数:analysis_project_id
或:decision_project_id
。我该如何更改,以便仍然收到:project_id
?
我不想自定义配置控制器,以便知道它嵌套在不同的资源中。
答案 0 :(得分:0)
就是这样,您无需在此处发送params
,它会自动与您的action
对应。
resources :analysis do
resources :configuration
end
如果你需要这样的路线
analysis_configuration_index GET /analysis/:analysis_id/configuration(.:format) configuration#index
POST /analysis/:analysis_id/configuration(.:format) configuration#create
new_analysis_configuration GET /analysis/:analysis_id/configuration/new(.:format) configuration#new
edit_analysis_configuration GET /analysis/:analysis_id/configuration/:id/edit(.:format) configuration#edit
analysis_configuration GET /analysis/:analysis_id/configuration/:id(.:format) configuration#show
PATCH /analysis/:analysis_id/configuration/:id(.:format) configuration#update
PUT /analysis/:analysis_id/configuration/:id(.:format) configuration#update
DELETE /analysis/:analysis_id/configuration/:id(.:format) configuration#destroy
analysis_index GET /analysis(.:format) analysis#index
POST /analysis(.:format) analysis#create
new_analysis GET /analysis/new(.:format) analysis#new
edit_analysis GET /analysis/:id/edit(.:format) analysis#edit
analysis GET /analysis/:id(.:format) analysis#show
PATCH /analysis/:id(.:format) analysis#update
PUT /analysis/:id(.:format) analysis#update
DELETE /analysis/:id(.:format) analysis#destroy