Start your client side out right
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
gemfiles Update test dependencies. Happy now, gemnasium? Jun 26, 2012
lib Run eastwood initializer for all gem groups Jan 8, 2013
spec Correct interpolate to ignore missing keys May 21, 2012
.rvmrc Ruby 1.9.3 baby Jan 20, 2012
Appraisals Begin testing against rails 3.1.0 Feb 27, 2012
Gemfile Moving to appraisals and rspec for testing Feb 23, 2012
Gemfile.lock Update test dependencies. Happy now, gemnasium? Jun 26, 2012
LICENSE Add i18n to readme Jun 26, 2012
Rakefile Include appraisal install as prerequisite to default rake task Feb 27, 2012


Start your client side out right.

Build Status Dependency Status


Eastwood brings your Rails routes to the client side in a slick, unobtrusive way.

As of v0.3.2, Eastwood supports Rails >= 3.1.0, which means both ActionDispatch and Journey routers are supported.


Include eastwood in your gemfile:

gem 'eastwood'

Then mount the engine wherever you want:

mount Eastwood::Engine => '/eastwood'

The place you mount the engine actually doesn't make much of a difference right now. The engine itself has no routes, just a single javascript asset you can include through the pipeline.

Finally, require eastwood.js in your javascript manifest.

#= require eastwood


Eastwood will give you a namespace for your application, as well as all of your named route helpers converted to javascript functions. If your app is named MyApp, requiring the Eastwood javascript will give you something like this available on window:

MyApp : {
  env : 'development',
  routes : {
    new_user_path : function( format ){
      // javascript to return you a string route, with segment keys
      // interpolated, and including either the format you specify
      // or the default 'json'.

This namespace is also a great place to put the rest of your client-side code!


Create a config/initializers/eastwood.rb and you can do the following:

Eastwood.configure do |config|
  config.default_route_format = :json         # pass false or '' to omit it entirely
  config.javascript_route_style = :underscore # or :camelcase
  config.javascript_namespace = 'MyApp'       # defaults to your app name
  config.excludes << /admin/                  # add patterns here to exclude routes from being exported


Eastwood can include arbitrary "routes" for the client-side too. In your configure block:

Eastwood.configure do |config|
  config.hash :foo, '#/foo'
  config.hash :bar, '/bar/:id'

This will give you foo_hash and bar_hash as functions in MyApp.routes, with all segments interpolated as you would expect.


Eastwood can also export arbitrary values to the client side:

Eastwood.configure do |config|
  config.export :foo => 'bar', :baz => 123.45

Pro Tips

Eastwood plays really well with Sammy.js:

# include all of our eastwood routes as sammy helpers
@helpers MyApp.routes

# ...

# use our eastwood routes in the event context
@render @clients_path( 'wal' ), result, -> $( '#clients' ).html @content

It also plays well with backbone and friends with a little configuration:

# mix-in route helpers into backbone prototypes
_( Backbone.Model.prototype  ).extend MyApp.routes
_( Backbone.Router.prototype ).extend MyApp.routes

Eastwood even plays well with client-side templating solutions that treat functions like first-class citizens like, ahem, walrus:

  <a href="{{@clients_path( 'html' )}}">Clients</a>

I18n (work in progress)

Eastwood will also be able to export your i18n to the client side. Simply:

#= require eastwood/i18n

And your translations will be attached to your namespace. Afterwards, use MyApp.t( '' ) to look up translations. t accepts a hash as a second parameter to use as the context for any interpolation the translation string needs.


Since Sprockets doesn't know when your context helpers change, you may need to clear out your sprockets cache when you change your routes. Just run rake tmp:clear.


Eastwood is released under the MIT license.