Reputation: 364
I have this routes
resources :posts, :controller => 'frontend/posts' do
resources :photos, :controller => 'frontend/posts'
end
So frontend/posts_controller
handles these requests:
/posts/:post_id/photos/:id
/posts/:id
Somtimes the :id
means the photo id and in some cases the post id.
I want that post always uses :post_id
. Is it possible to rename :id
in :post_id
without adding custom(match
...) routes?
thanks.
Upvotes: 1
Views: 469
Reputation: 14029
I'm not sure if this helps or just goes further down the rabbit hole but can't you force it to be like that with:
match "posts/:post_id" => "posts#show"
Upvotes: 0
Reputation: 211610
You should just write your finders to handle both cases. It's easier than messing around with parameter names:
@post = Post.find(params[:post_id] || params[:id])
That being said, I agree that it's annoying that the :id
parameter changes names depending on the depth of the resource call.
Upvotes: 1
Reputation: 7586
The presence of :post_id is what will differentiate between the two routes. Personally, unless I have a compelling reason to depart from convention, I try to avoid it.
Upvotes: 1