Skip to content

Instantly share code, notes, and snippets.

@cdimartino
Created February 22, 2016 17:14
Show Gist options
  • Save cdimartino/8fb3512a677c1e4a5737 to your computer and use it in GitHub Desktop.
Save cdimartino/8fb3512a677c1e4a5737 to your computer and use it in GitHub Desktop.
Sinatra routes - avoiding capture variable naming collisions

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment