I want to have consistency in naming convention of my routes. Default param is :id
for any resource. However if one nests another resource in it, param of parent resource changes to :parent_id
.
My routing looks like:
resources :users do
resources :projects do
resources :issues
end
end
For user model it would generate url like :id
, for project url will be :user_id/:id
and for issues url will be :user_id/:project_id/:id
. I tried to overload the default param following this
resources :users, param: :user_id do
resources :projects, param: :project_id do
resources :issues, param: :issue_id
end
end
It generates url like: :user_user_id/:project_project_id/:issue_id
. Since I am overriding it I would want that that default appending of parent resource is off. I want my routes to look like :user_id/:project_id/:issue_id
and I want it to be consistent for all the models. ie project should be mapped to :user_id/:project_id
.
scope(as: :project)
to correct url_helpers. This solution is superior to the accepted as it allows changing the param key to anything, even if it does not include the parent resource name – Overtrade