Skip to content

Instantly share code, notes, and snippets.

@fj
Created May 31, 2012 04:10
Show Gist options
  • Save fj/2840961 to your computer and use it in GitHub Desktop.
Save fj/2840961 to your computer and use it in GitHub Desktop.
DRYer way to do this route-drawing?
MyApp::Application.routes.draw do
resources :fruits
resources :vegetables
resources :sandwiches
resources :desserts
resources :meats
resources :baskets do # DRYer way to do this?
resources :fruits # repeated route! :(
resources :vegetables # repeated route! :(
resources :sandwiches # repeated route! :(
resources :desserts # repeated route! :(
resources :meats # repeated route! :(
end
resources :refrigerators do
# ... repeats again
end
resources :freezers do
# ... repeats again
end
end
@fj
Copy link
Author

fj commented May 31, 2012

@cgriego That's a good point. Yes, the fruit resource is always the same.

But the information we might want to render in each view is different (e.g. "you're looking in refrigerator #234, which contains fruit #42" would only be shown on /refrigerators/234/fruits/42, and not, say, /baskets/456/fruits/42 or /fruits/42).

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