Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Brings Rails named routes to javascript
tag: v0.2.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
Gemfile
Gemfile.lock
LICENSE.txt
Rakefile
Readme.md
VERSION
jsroutes.gemspec

Readme.md

JsRoutes

Generates javascript file that defines all Rails named routes as javascript helpers

Intallation

Your Rails Gemfile:

gem "jsroutes"

Your application initializer, like config/initializers/jsroutes:

JsRoutes.generate!(
    :file => "#{Rails.root}app/assets/javascripts/routes.js",  # This is default
    :default_format => "json"                         # Default is blank
)

Usage

This will create a nice javascript file with Routes object that has all the rails routes available:

Routes.users_path() // => "/users"
Routes.user_path(1, {format: 'json'}) // => "/users/1.json"
Routes.urer_project_path(1,2, {q: 'hello', custom: true}) // => "/users/1/projects/2?q=hello&custom=true"

In order to make routes helpers available globally:

$.extend(window, Routes)

Have fun

Something went wrong with that request. Please try again.