JavaScript Routes plugin
Plugin details
Documentation
ruby script/plugin install git://github.com/toretore/javascript_routes.git
Using
The plugin will generate public/javascripts/routes.js when the application starts. The file will vary in size depending on how many routes you have in routes.rb. The “required” parts are around 3kb. To use it, simply include it like any other JavaScript file in your layout:
< script type="text/javascript" src="/javascripts/routes.js">< /script>
The file will define two objects that will be available to the browser. A Route encapsulates a single route, while Routes contain all routes (it’s an array). Routes.named contains all the named routes. To generate a route, call Routes.generate:
Routes.generate({controller:'foo', action:'foo'}) Routes.generate({controller:'bar', action:'baz', baz:'quux'}, {host:'example.com'})
The generate function takes an object (hash) with name/value mappings and an optional options object. If no routes are found to match the parameters, it will return false. The available options are:
onlyPath Don’t include the domain
includeSlash Include the last slash in the path
escape Set to false to prevent the escaping of special characters
protocol Protocol other than ‘http://’ to use
host Hostname
port Port number
If you want to use a named route, it will have defined a convenience method on the Routes object:
Routes.home() Routes.articles() Routes.article(1) Routes.article({id:1, foo:'bar'})
These functions can, like their Rails equivalents, take either a hash with name/value mappings, or all required arguments in the correct order. They also take an optional second (or last) argument options.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, 26 days ago

