-
-
Save heavysixer/84e8f173925b81cb20eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Routes.build({ | |
:controllers => ['application', 'home'], | |
:home => ['index','about','tos'], | |
:application => ['index'], | |
:resources => ['categories','accounts'] | |
:categories => { | |
:collections => ['browse'], | |
:member => ['purchase'] | |
:resources => ['shirts'] | |
:shirts => { | |
:member => 'show' | |
} | |
} | |
}) | |
/* | |
Adding a controller gives you only the actions you specify inside property. | |
So for example we define two general controllers "Application", and "Home". This means | |
that the router will resolve routes: | |
/application/index | |
/home/index | |
/home/about | |
/home/tos | |
If you add a controller to the resources array then you also get all the normal crud methods. For example the Categories controller would get these routes automatically | |
/categories/index | |
/categories/new | |
/categories/1/edit | |
/categories/create | |
/categories/1/destroy | |
Additionally you can specify collection and member routes like you do in Rails e.g. | |
/categories/browse | |
/categories/1/purchase | |
Finally, you can also nest an arbitrary number of resources inside a resource by specifying a resources attributes. In our example shirts are a nested resource of products. Which means we get these routes | |
/categories/1/shirts/index | |
/categories/1/shirts/new | |
/categories/1/shirts/1/edit | |
/categories/1/shirts/create | |
/categories/1/shirts/1/destroy | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Might I propose this: