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?
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.
It won't be problematic to use jquery with rails at all, it's just not the natively supported JavaScript library. You don't actually have to use any of the JavaScript builtins in rails, and the (by default) RESTful structure of your application should make AJAX simple.
With prototype and scriptaculous, alot of the AJAX work has already been done for you. With jquery, you'll just be writing some more JavaScript yourself.
Rails was built to work with Prototype for AJAX et. al., but there's no reason you have to use Prototype. I'm a jQuery fan myself, and you can definitely use it with Rails.
You can still hook into a lot of the AJAX work that's been done in Rail with jQuery, not a problem.
And, as kmorris said, if you're using jQuery and any other javascript library on the same site, be sure to add the jQuery.noConflict()
line in or else VERY bad things will happen.
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
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