Hartator
Hartator

Reputation: 5145

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

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_success'
...

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 :

Upvotes: 6

Views: 2273

Answers (3)

Andrea Pavoni
Andrea Pavoni

Reputation: 5311

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/

Upvotes: 3

adc
adc

Reputation: 437

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

Upvotes: 0

Max Williams
Max Williams

Reputation: 32933

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/

Upvotes: 0

Related Questions