开发者

What defines RJS? confused with what I have Read

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 th开发者_如何学Ce 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜