开发者

Switching from prototype to jquery in Rails, what about helpers?

开发者 https://www.devze.com 2023-03-08 18:40 出处:网络
I currently switching from prototype to jquery mainly to support simple ajax file upload. I use : https://github.com/indirect/jquery-rails

I currently switching from prototype to jquery mainly to support simple ajax file upload. I use : https://github.com/indirect/jquery-rails

95% of javascript code is made by rails helper such as :

- remote_function
- render :update do |page|
- page.replace_html 'id', :partial => 'content'
- page['form']['name'] = something
- page.visual_effect :highlight, 'head_suc开发者_如何学Gocess'
...

I understand that the 5% of code purely prototype I have to rewrite it for Jquery, but what about the rest ? Do I have to rewrite it all in raw jquery ?

I use :

  • Rails 3.0.7
  • jquery-rails 1.0.7


all that helpers are deprecated in favor of unobtrusive javascript (it doesn't matter if you're using jQuery or PrototypeJS).

you can find a detailed guide here:

http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/


The jrails plugin/gem converts the rails prototype helpers (like page.replace_html, page.visual_effect) to use jquery instead of prototype. Use that and you won't have to change any of your code, except the pure prototype code as you say.

http://mirror.ozdiy.com/assets/b8/2f96a12bc919b37e09d303b86ea1b9_1251811910.html

https://github.com/aaronchi/jrails/


The jQuery-rails gem has a rake :install task that when run updates the rails.js helper and replaces prototype.js with jquery.js

0

精彩评论

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