Rails UJS Behaviors for jQuery and Zepto
CoffeeScript Ruby Other
Latest commit bb175b2 Jun 5, 2015 @josh Merge pull request #43 from josh/josh-patch-1
Failed to load latest commit information.
script Add `script/test` and `script/server` Mar 8, 2015
test Extend `data-confirm` behavior to `<input type=submit>` elements Mar 8, 2015
vendor Test against newest jQuery 2.1.3, Zepto 1.1.6 Mar 8, 2015
.gitignore Add gitignore Jan 23, 2014
.travis.yml Add `script/test` and `script/server` Mar 8, 2015
Gemfile Add Gemfile Jan 23, 2014
Gemfile.lock Add Gemfile Jan 23, 2014
LICENSE Update copyright year Dec 12, 2012
README.md Deprecate this Jun 5, 2015
Rakefile Move source files to root dir Sep 17, 2012
accept.coffee Move source files to root dir Sep 17, 2012
bower.json Rails Behaviors 0.8.4 Mar 8, 2015
confirm.coffee Extend `data-confirm` behavior to `<input type=submit>` elements Mar 8, 2015
csrf.coffee Revert "use URL api instead of anchor tags" Mar 8, 2015
disable.coffee Move source files to root dir Sep 17, 2012
method.coffee Move source files to root dir Sep 17, 2012
prepare.coffee Fix `submit:prepare` trigger as a result of mouse click Jan 23, 2014
remote.coffee Keep reference to remote-xhr object Feb 26, 2013
remote_submit.coffee Move source files to root dir Sep 17, 2012


Rails Behaviors (Deprecated)

Rails Behaviors implements the data-* behaviors generated by Rails 3.x.

This is an alternative to jquery-ujs. First, it is all CoffeeScript goodness — well, that's mostly good for me! Second, it is written in a modular fashion. This makes it possible to cherry pick the components you need and replace specific functionaly without having to rewrite the entire library. Third, it uses built-in global ajax events rather than adding its own. O, one more thing, Zepto.


jQuery 1.7.2+ or Zepto 0.8+

You'll need Sprockets 2 if you want to use the gem version.


rails-behaviors is distributed through the bower package manager.

bower install rails-behaviors


For testing you will need:

  • Ruby 1.9.3+
  • Bundler (gem install bundler)
bundle install
bundle exec rackup -E test ./test/config.ru
# now open the browser at http://localhost:9292

Migrating from jquery-ujs

This library handles all the data-* behaviors defined in Rails, so it is roughly feature for feature identicial in your Views.

The differences are in the JavaScript.

  1. There are no ajax:* events. jQuery already has global ajax events built in, so there is no point in duplicating that functionality. Doing a find and replace for "ajax:" events should give you a good start. You're looking to replace ajax:success with ajaxSuccess, ajax:error with ajaxError, etc.
  2. There are no global configuration options. Theres no equivalent for $.rails. You probably should have never used that in the first place.

NOTE: You cannot use rails-behaviors and jquery-ujs at the same time.


See josh.github.com/rails-behaviors for a markup and event reference.



$ git clone git://github.com/josh/rails-behaviors.git
$ cd rails-behaviors/
$ bundle install

Run tests:

$ rackup -p 3000 test/config.ru
$ open http://localhost:3000/


Copyright © 2011 Joshua Peek <josh@joshpeek.com>

Rails Behaviors is distributed under an MIT-style license. See LICENSE for details.