开发者

The situation about Rails/JQuery/Prototype/RJS

I am trying to use Jquery / ajax in rails 3.0.7. I do not und开发者_如何学Goerstand 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."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜