Batman.js and Rails
Ruby on Rails isn't required for a batman.js app, but there are some helpers for Rails-batman.js integration.
batman-rails is a Ruby Gem which allows you to easily use batman.js inside a Rails 3.2+ application. It takes care of a number of things for you:
- Vendoring the batman.js source into your app
- Generating your project structure within your Rails app
- Preloading HTML templates for batman.js
Getting the gem is simple. Simply add the following line to your
Then simply tell
bundler to install it:
$ bundle install
batman-rails is installed, we can use the normal Rails generator system to generate the skeleton for our batman.js application.
$ rails generate batman:app
The structure of this app will be exactly the same as described in Directory Structure, but it will live within our Rails app folder. You can find your newly created app in
batman-rails comes with a view helper to preload your batman.js templates. This way, batman.js won't have to request them by AJAX.
<head> <!-- ... --> <%= batman_define_views %> </head>
batman_define_views also takes a
path: option, in case your HTML isn't in
If you don't want to use the version of batman.js provided by
batman-rails, you can provide a version yourself. You might do this if you wanted to use a prerelease version of batman.js.
- Get a version of batman.js and put it in
Remove from your app's coffee file:
#= require batman/batman
In its place, add:
#= require lib/batman