Unobtrusive Javascript for Rails is a Rails plugin that lets you attach behaviours to your page elements using pure Ruby with a little bit of CSS selector magic, in an unobtrusive manner, including patches to Rails' built-in AJAX/Javascript helpers to make them unobtrusive.

You can do something as simple as:

    <div id="my_funky_box">Click Me!</div>

    <% apply_behaviour "#my_funky_box:click" do |page|
        page.alert "You clicked me!"
      end %>
Or even simpler:

    <%= content_tag "div", "Click Me!", :onclick => "alert('Hello World!')" %>
All behaviours will be extracted to an external javascript file, generated at runtime, helping to ensure behaviour is separated from content and presentation.

More info:


Plugin Documentation: