An unobtrusive Javascript plugin for Rails 2.3, inspired by Rails 3.0
Use form_for
, link_to
or 'button_to' as you normally would, passing the :remote => true
option when you want the form or the link to be submitted using an XMLHttpRequest and the results of the request evaled in the context of the page.
-
Overrides
form_for
,link_to
, andbutton_to
so that they emit HTML5-like tags withdata-remote
anddata-method
attributes instead of the current inline javascript style. -
Extends the
javascript_include_tag :defaults
so that it loadsremotable.js
which provides the javascript code that transparently takes care of firing an XMLHttpRequest for any link or form with thedata-*
attributes and evaluates the response in the context of the page. (jQuery 1.4 required)
-
It doesn't support any of the
:update => { :success => "posts", :failure => "error" }
style options. You have to use RJS, or just pure javascript, in your response in order to manipulate any HTML elements on the page. -
It only accepts
GET
as a:method
forlink_to
. If you need an element that looks like a link but updates or destroys a resource, the usebutton_to
and style the button with CSS to look like a link.
It should be trivial to write your own remotable.js
and drop it in as a replacement for javascripts/remotable.js
The following gist provides a sample implementation for Prototype 1.6 and jQuery 1.3.2 (with livequery)
- Override
remote_form_for
,link_to_remote
,button_to_remote
to use remotable
Copyright (c) 2010 Christos Zisopoulos, released under the MIT license