You MUST name your capture variables uniquely in your routes. The convention is that the object farthest to the right is the primary object being acted upon. Thus the implicit :id belongs to it, and all other :id type fields must be explicitly named:
Anti-Pattern
post '/posts/:id/comments/:id/upvote' do
end
Anti-Anti-Pattern
post '/posts/:post_id/comments/:id/upvote' do
end