views:

90

answers:

1

I have a rails3 project where I need to use prototype together with jquery - using the current Ruby on Rails 3 RC1 there is no example or documentation to use both together without problems.

Is there a setup instruction or did anyone get both javascript frameworks running with the latest rails version?

thanks, z3cko

+2  A: 

Have you tried jQuery.noConflict()? I'm running a Rails 3 rc app with both Prototype and jQuery using the no conflict function - the jQuery bit is working fine, not too sure about Prototype at the moment though.

Add jQuery.noConflict(); to your application.js file - that gives control of the $ call back to Prototype, so jQuery calls have to be tagged with 'jQuery', rather than '$' eg. jQuery.getJSON instead of $.getJSON. Alternatively, you could define a variable: var $j = jQuery.noConflict(); - the previous example would then become $j.getJSON. Finally, you can also keep jQuery code with $ whilst using jQuery.noConflict() by wrapping it in another function:

(function($) {
//your code in here
})(jQuery);
Sonia
thanks for your comment! can you please be more specific? where did you set jQuery.noConflict() and what is your load order of the libraries?
z3cko
I've updated my comment to be a bit more specific, hope that helps!
Sonia