简体   繁体   中英

The situation about Rails/JQuery/Prototype/RJS

I am trying to use Jquery / ajax in rails 3.0.7. I do not understand what is the current situation about Jquery and rails.

Everywhere there is tons of hacks and plugins and scripts to use JQuery. So :

  • Is there an "official way" to use jquery in rails 3.0.x or are all method just customs hacks?
  • Is there a rjs or equivalent with Jquery for rails 3.0.x ?
  • What are all those jquery something files for rails, when jquery official site only propose one file?
  • From what i saw protoype is easy to use for ajax, why is it dropped in favor of jquery for rails 3.1.x?

As of Rails 3, the JavaScript library you use is up to you. There are "drivers" created for the Rails primitives for Prototype and for jQuery. To set up jQuery, simply include the jquery-rails gem in your bundle file:

gem "jquery-rails"

...then run bundle install .

If you don't already have jQuery installed in the project, you can run this command to install it:

rails generate jquery:install

In Rails 3.1, jQuery is the default, rather than Prototype. I personally believe it's because jQuery plays well with other JavaScript libraries, and that flexibility makes it more appealing to something like Rails. However, there are tons of arguments on all sides. I'm not sure if there's a definitive reason besides "jQuery is the new hotness."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM