Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Brings Rails named routes to javascript

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Readme.md
Octocat-spinner-32 VERSION
Octocat-spinner-32 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.