开发者

Is jRails a must for Rails + jQuery?

i'm new to rails (using rails 2.3.10) and would like to use jquery in particular jquery ui. the project is a brand new project and i'm planning to use some widgets from jquery ui like datapicker and selectable, etc. i having been hearing that jrails can be installed to replace prototype in rails2 and i have the following questions开发者_如何转开发.

  1. what is the difference between rails with and without jrails in term of developing a new rails app?
  2. what is the advantage of using jrails?
  3. is jrails a must for using jquery ui widgets in my rails app?
  4. any recommended tutorials of integrating jquery plugins in particular jquery ui selectable widget into a rails app?

thanks batterhead


First up, if you're writing a brand new project, I would recommend considering using Rails 3. Among other things, it actually abstracts away the default JS framework used by Rails, so it's much easier to remove Prototype entirely from Rails 3.

As far as using jQuery UI, nothing is stopping you from including jQuery and jQuery UI in the project. Prototype and jQuery can live together in your app just fine (though you need to set a flag so that jQuery doesn't override prototype's "$" function; how to do that is another question).

The only reason jRails was written is because of the RJS features of Rails 2 -- the ability to write javascript templates on the server. Prototype is intrinsically linked to the RJS functionality of Rails, as all the helper methods for RJS would translate to Prototype calls. In Rails 3, that functionality has been deprecated in favor of using more unobtrusive javascript (UJS) techniques, so all the JS code stays on the client side. Thus, the reliance on Prototype is no longer an issue in Rails 3.


TL;DR

  1. Without jRails, all javascript generated server-side will translate in to prototype javascript calls on the client-side -- RJS template helper methods, link_to :method => :delete calls, etc.

    With jRails, all those server-side methods will translate in to jQuery calls client-side instead.

  2. See above; a Rails 2 app's server-side helpers that generate javascript will use jQuery instead of prototype.

  3. No. jRails only affects the javascript generated server-side.

  4. You can include and use jQuery in your app in the same way you would include any other javascript resource in Rails 2. Once jQUery is included, its no different to using it on plain HTML, so look at the jQuery UI tutorials on how to use the datepicker or selectable.

Also, use Rails 3, not Rails 2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜