Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

finished router docs

  • Loading branch information...
commit e281510eaeaa75e9199e07cc979b01f144cf54ab 1 parent fe83a21
@Techwraith Techwraith authored
Showing with 78 additions and 8 deletions.
  1. +78 −8 docs/2-router.md
View
86 docs/2-router.md
@@ -1,38 +1,108 @@
-Geddy uses [Barista] as it's router. Its API is very similar to rails routes. Both general purpose resource based routes and individually defined routes are possible.
+Geddy uses [Barista](http://github.com/kieran/barista) as it's router. Its API is very similar to rails routes. Both general purpose resource based routes and individually defined routes are possible.
* * *
#### .match
-docs coming soon
+`router.match( path [, method] )`
+
+##### path
+- `path [string]`: the url to match to an action
+
+##### method
+- `method [string]`: the http method to match
+
+##### examples
+```
+router.match(‘/‘).to(‘Main.index’);
+// will route any request to ‘/‘ to the Main controller’s index action
+
+
+router.match( '/products/:id', 'GET' ).to( 'products.show' )
+// will route ‘/products/5’ to Products.show()
+// and set the id paramer to be 5
+
+
+router.match( '/profiles/:username', 'GET' ).to( 'users.show' )
+// will route ‘/products/dan’ to Users.show()
+// and set the username paramer to be dan
+
+
+router.match( '/products/:id(.:format)', 'GET' ).to( 'products.show' )
+// things enclosed in parentheses are optional
+```
* * *
#### .to
-docs coming soon
+`router.match( path ).to( action )`
+
+defines the action`to map the path to.
+
+##### action
+- `action [string]`: a controller name plus an action name as a string
+- `action [object]`: an object that defines a controller and action property
+
+##### examples
+```
+router.match(‘/‘).to(‘Main.index’);
+// will route any request to ‘/‘ to the Main controller’s index action
+
+
+router.match(‘/‘).to({controller: ‘Main’, action: ‘index’});
+// will route any request to ‘/‘ to the Main controller’s index action
+```
* * *
#### .get
-docs coming soon
+`router.get( path )`
+
+Equivalent to `router.match( path, 'GET' )`
* * *
#### .post
-docs coming soon
+`router.post( path )`
+
+Equivalent to `router.match( path, ‘POST’ )`
* * *
#### .put
-docs coming soon
+`router.put( path )`
+
+Equivalent to `router.match( path, ‘PUT’ )`
* * *
#### .del
-docs coming soon
+`router.del( path )`
+
+Equivalent to `router.match( path, ‘DELETE’ )`
* * *
#### .resource
-docs coming soon
+`router.resource( controller )`
+
+generates standard resource routes for a controller name
+
+##### controller
+- `controller [string]`: the camelCased controller name that needs resourceful routes
+
+##### examples
+```
+router.resource( 'products' )
+
+// is equivalent to:
+
+router.get( '/products(.:format)' ).to( 'products.index' )
+router.get( '/products/add(.:format)' ).to( 'products.add' )
+router.get( '/products/:id(.:format)' ).to('products.show' )
+router.get('/products/:id/edit(.:format)' ).to( 'products.edit' )
+router.post('/products(.:format)' ).to( 'products.create' )
+router.put('/products/:id(.:format)' ).to( 'products.update' )
+router.del('/products/:id(.:format)' ).to( 'products.destroy' )
+```
* * *
Please sign in to comment.
Something went wrong with that request. Please try again.