Skip to content

Instantly share code, notes, and snippets.

@codeodor
Created October 24, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeodor/3947693 to your computer and use it in GitHub Desktop.
Save codeodor/3947693 to your computer and use it in GitHub Desktop.
How do I keep all of these routes, but also make them available under a scope?
# I have read http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html#method-i-resources
# and remain clueless.
MyApp::Application.routes.draw do
resources :blogs do
resources :comments
end
# then imagine tons of routing below this
end
# So above, we can see we have routes with paths:
# /blogs
# /blogs/comments
# However, I want to create snapshots of the database periodically and make them
# available via:
#
# /snapshots/:snapshot_id/blogs
# /snapshots/:snapshot_id/blogs/comments
# The URLs above should go to the same controllers/actions as my original
# routes file defines.
#
# Also, the original /blogs and /blogs/comments should be available without the snapshot stuff.
#
# My idea here is that application_controller.rb will figure out when a
# snapshot is being requested, and switch the DB accordingly.
# So, I know I'm dense. How do I do that? Thanks!
@codeodor
Copy link
Author

So basically, imagine it's a long set of complex routes. I don't want to copy all of the routes into this new scope and maintain 2 copies. I want to just say "if you see a request for /snapshots/:snapshot_id/ then please stick :snapshot_id into the params and go to "

@codeodor
Copy link
Author

Ugh, forgot to preview. Here we go again:

So basically, imagine it's a long set of complex routes. I don't want to copy all of the routes into this new scope and maintain 2 copies. I want to just say "if you see a request for /snapshots/:snapshot_id/[some other route in the system] then please stick :snapshot_id into the params and go to [some other route in the system]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment