1

I am a little confused from what I have read on stackoverflow regarding RJS.

Many people have stated that Rails 3.0 has dropped RJS for UJS .This statement confuses me because from what I understand the difference between obtrusive (inline) and unobtrusive JavaScript doesn't define RJS itself.

Isnt RJS the act of using JavaScript templates and having AJAX calls return code which is in turn executed at the clients end, as opposed to the non-RJS route of having the app return JSON or XML, i.e. just the data, and having the client side JavaScript deal with it?

If what I have said is correct Rails 3.0 does support RJS and you can use UJS with RJS, although I believe support in 3.1 will be separated into optional gem(s).

Example:- UJS used with index.erb and in application.js but data is returned in index.js.erb therefore UJS is used with RJS

2 Answers2

1

You're right, it's sometimes confusing. My point of view is that:

  • UJS appeared with Rails 3

  • RJS will be extracted as a gem in Rails 3.1

  • UJS and RJS only have JS in common

apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • I believe RJS support will be apart of the prototype-rails gem any idea if you can drop JQuery support back with JQuery-UJS to get both JQuery and RJS? –  May 22 '11 at 16:09
1

RJS is just another type of view template. It allows you to write Ruby instead of JavaScript. For example, update.js.erb using jQuery:

$("#data").html("<%= escape_javascript render(:partial => 'data') %>");
$("#loading_indicator").hide();

and update.rjs:

page.replace_html 'data', :partial => 'data'
page.hide 'loading_indicator'

RJS depends on Prototype and Scriptaculous (links are to Ruby documentation for the helpers). See this SO question/answer for some more details on RJS and Rails 3.1.

Community
  • 1
  • 1
Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311