Skip to content

Instantly share code, notes, and snippets.

@heavysixer
Created June 8, 2012 16:57
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 heavysixer/84e8f173925b81cb20eb to your computer and use it in GitHub Desktop.
Save heavysixer/84e8f173925b81cb20eb to your computer and use it in GitHub Desktop.
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
*/
@drewblas
Copy link

Might I propose this:

Routes.build (r) ->
  r.controller 'application', (a) ->
    a.get 'index'
  r.controller 'home', (h) ->
    h.get 'index', 'about', 'tos
  r.resource 'accounts'
  r.resource 'categories', (c) ->
    c.collection 'browse'
    c.member 'purchase'
    c.resource 'shirts, (s) ->
      s.member 'show

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