Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery + Rails problematic, is that true?

I saw comments in a previous question saying that it is best to use Prototype with Rails. However, my own experience is that Jquery is a superior Javascript library. Being new to Rails, I have not yet investigated how to use Jquery with Rails but I assumed this would work. Is it correct that this may be a problematic combination - especially in relation to Ajax - and that I may need to use Prototype instead?

like image 767
Hola Avatar asked Jun 04 '09 17:06

Hola


3 Answers

I've worked on all my projects since 3 years with rails and (exclusively) jquery. Never really encountered any (serious) problems so far.

There is a plugin called jrails, which acts as a drop-in replacement for prototype.

http://github.com/aaronchi/jrails/tree/master

Update: with it you can get all of the same default Rails helpers for javascript functionality using

like image 104
seb Avatar answered Oct 17 '22 15:10

seb


I use both jQuery and Prototype with rails. jQuery for DOM manipulation and thickbox (my favorite light box plugin), but i use prototype for AJAX right now. no particular reason, just haven't wanted to use the jrails plugin yet. im sure i will do this in the future. if you use both, this should be in your head tag:

    <%= javascript_include_tag 'prototype' %>
    <%= javascript_include_tag 'jquery' %>
    <script type="text/javascript">
        var $j = jQuery.noConflict();
    </script>

Then use jQuery with $j

like image 28
Tony Avatar answered Oct 17 '22 14:10

Tony


I use jQuery and Rails on the job in a production environment and have only nice things to say. We use AJAX too. The only problem I can think of is the jQuery.noConflict() call that's necessary if you're using jQuery and prototype together.

like image 42
kmorris511 Avatar answered Oct 17 '22 13:10

kmorris511