views:

2954

answers:

4
+4  Q: 

jRails Alternative

Hello,

do you know an alternative to jrails?

It's more or less outdated (uses jQuery 1.5 - now 1.7 is the current release).

Does anybody know an alternative?

Thanks

EDIT:

I know how to build the rails helper with jquery allone - but I like the rails helpers, so I dont want to use jquery allone (without jrails)

+1  A: 

Right now there's no real alternative. However, you can install jRails then upgrade the jQuery installation simply replacing the javascript files (except jrails.js) in the javascripts folder.

The only issue I'm aware of about jRails is that current version isn't compatible with Ruby 1.9.

Simone Carletti
A: 

I was in the same position of looking for an alternative a couple months ago. I ended up writing my own jquery in .js.erb files, and I would recommend that. Javascript isn't nearly as painful when using jQuery.

zgchurch
+18  A: 

Having always used the Prototype helpers with Rails, I recently decided to move over to using JQuery. At first I looked at JRails, since it was a drop-in replacement and hence would require minimum effort.

BUT! After reading more about JQuery and playing around with it, it became apparent to me that the best way to use Rails and JQuery together is to handle it all yourself. This might sound like a more complicated, time consuming approach but it's honestly not! I see this approach as giving you two main benefits:

  • All your Javascript can be unobtrusive -- this won't be the case with JRails
  • You can use JQuery in .js.erb templates rather than using RJS templates, which gives you much finer control and is easier for front-end designers who are familiar with JQuery to get to grips with (the indirection of RJS, with it's Page object, is often confusing)

So, I recommend the first thing you do is watch the excellent JQuery Railscasts: http://railscasts.com/episodes/136-jquery. It's only a few minutes long and you'll be amazed at how easy and elegant it is to write AJAX code using JQuery and Rails.

You'll obviously need to get up to speed with JQuery too, but there are many excellent resources out there for this. JQuery is such an desirable skill these days, you'll be really thankful you took this approach.

Olly
agreed, have you seen the pollution that the rails helpers cause in your html?
Omar Qureshi
+1. jrails really seems to be a bit out-of-date. anyway, learning jquery requires only a little amount of work but the benefits are huge. forget jrails.
Christoph Schiessl
I won't accept this answer, because I don't want to switch fully to jQuery (without rails) - that wasn't the question. I like the answer from weppos, but I'll wait if somebody adds another answer.
Lichtamberg
A: 

using Rails 2.3.5 and jQuery 1.4.2, I needed to add the {render :layout => false} option in format.js statement in the controller:

respond_to do |format|
  format.js { render :layout => false }
end

Hope that Helps, Nelson

nelsonenzo