Your routes, in JavaScript
Find a file
2010-01-27 17:08:55 +10:30
bin Initial commit 2008-04-17 11:47:13 +02:00
lib Minor vertical spacing 2009-06-10 15:03:02 +09:30
tasks Plugins shouldn't load the environment as this creates circular dependencies. 2010-01-27 17:08:55 +10:30
test Initial commit 2008-04-17 11:47:13 +02:00
init.rb Removed auto-generate on boot, as routes don't seem to load at time of init 2009-06-10 14:56:46 +09:30
install.rb Initial commit 2008-04-17 11:47:13 +02:00
Rakefile Initial commit 2008-04-17 11:47:13 +02:00
README Added README 2009-10-28 18:21:51 +10:30
uninstall.rb Initial commit 2008-04-17 11:47:13 +02:00

JavascriptRoutes
================
Rails routes get generated in JavaScript...


How it works
============
JavascriptRoutes::generate iterates over all your routes, using Rails inbuilt reflection,
then generates equivalent URI generators in JavaScript.

It can either do just named routes or both named and dynamic ones (from controller/action).
This is controlled by setting :lite to true or false.

The idea is you hook a call to JavascriptRoutes::generate() within your bootstrap code, 
and that dumps out a fresh public/javascripts/routes.js for you.

Setup
=====
# Add this to bootup (say in bottom of environment.rb or a config/initializer):
#
# Generate routes now...
JavascriptRoutes.generate(:lite => true)


# Add this to your application/template, and go ahead and access 'Routes' javascript object
<%= javascript_include_tag :routes %>

Example:

config/routes.rb
  map.resources :bookings

  # Namespaced works... 
  map.namespace(:ship) do |ship|
    ship.resources :reservations
  end


In your js (after including routes.js)

  // Urls for a new booking
  Routes.new_bookings_path();

  // Url to edit booking with id 23
  Routes.edit_booking_path(23);
  
  // Namespaced under 'ship' 
  // Editing url for reservation 1 
  Routes.edit_ship_reservation_path(1);

CREDITS
=======
Forked from 'toretore' / javascript_routes on github.