jQuery & Rails installation

I’m missing something basic …

How does one install jQuery in RoR?

On Jan 31, 2010, at 11:45 AM, Ralph S. wrote:

I’m missing something basic …

How does one install jQuery in RoR?

The old fashioned way. Download it from jQuery.com and stick the .js
files in public/javascripts. jQuery is not “supported” by the javascript
helpers in Rails. But if you’re doing unobtrusive javascript, you won’t
care.

Steve R. wrote:

On Jan 31, 2010, at 11:45 AM, Ralph S. wrote:

I’m missing something basic …

How does one install jQuery in RoR?

The old fashioned way. Download it from jQuery.com and stick the .js
files in public/javascripts. jQuery is not “supported” by the javascript
helpers in Rails.

But you can use the jrails plugin for that.

But if you’re doing unobtrusive javascript, you won’t
care.

And you should be doing unobtrusive JS, in which case Rails’ helpers are
indeed not much use.

FWIW, I just started using jQuery. I’m a bit underwhelmed with its
architecture. I may go back to Prototype, although I would like to get
to know both libraries better before I make that decision.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

There are several blog posts on how to use jQuery unobtrusively with
Rails. Yeah, don’t use the js helpers and RJS if you can avoid it!
I’m currently in the process of creating a jQuery application template
to install/configure jQuery widgets, jQuery UI and unobtrusive jQuery
in a Rails app.
Check my github rails3-templates at kristianmandrup.

Have fun!

BTW: If you want to learn jQuery, get the “jQuery in Action” book!

On Sun, Jan 31, 2010 at 7:35 PM, Kristian [email protected] wrote:

“jQuery in Action” is a very good book but make sure that you get
the 2nd edition which covers jQuery 1.4.

Cheers,

-Conrad

Ralph S. wrote:

I’m missing something basic …

How does one install jQuery in RoR?

Use the following line in your layout


<%= javascript_include_tag “jquery 1.2.3.4” %>


alternatively, you can copy jquery files to your javascript folder and
use :all option which will include/load all available javascript files


<%= javascript_include_tag :all %>


Note: you may encounter conflicts if you are using Prototype and Jquery
together. In that case, use


jQuery.noConflict(); and then instead of “$” use “jQuery”


Note: you may encounter conflicts if you are using Prototype and Jquery
together. In that case, use


jQuery.noConflict(); and then instead of “$” use “jQuery”


Somethng I am using … validates_captcha … uses Prototype.

Hmm … I wonder if this explains the odd behavior I am seeing when I
tried to use the jQuery plugin, IconDock:
http://icon.cat/wiki/IconDock_En#iconDock_jQuery_Plugin

So … I read
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
and my question is: What are the odds that there will be a conflict?

How can I find out definitely if validates_captcha conflicts with
jQuery?

Ralph S. wrote:

Note: you may encounter conflicts if you are using Prototype and Jquery
together. In that case, use


jQuery.noConflict(); and then instead of “$” use “jQuery”


Somethng I am using … validates_captcha … uses Prototype.

Hmm … I wonder if this explains the odd behavior I am seeing when I
tried to use the jQuery plugin, IconDock:
http://icon.cat/wiki/IconDock_En#iconDock_jQuery_Plugin

So … I read
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
and my question is: What are the odds that there will be a conflict?

How can I find out definitely if validates_captcha conflicts with
jQuery?

Remove jQuery and see what happens.

But really, if you use noConflict, there should be noIssue. :slight_smile:

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Ralph S. wrote:

Somethng I am using … validates_captcha … uses Prototype.

You could monkey-patch the render_regenerate_challenge_link of
the captcha provider to emit jquery specific javascript.

Or fork the project and make it js lib independent.

Martin

Martin Andert wrote:

Ralph S. wrote:

Somethng I am using … validates_captcha … uses Prototype.

You could monkey-patch the render_regenerate_challenge_link of
the captcha provider to emit jquery specific javascript.

Or fork the project and make it js lib independent.

That is sooo far over my head.

On Feb 6, 11:44 am, Ralph S. [email protected] wrote:

http://icon.cat/wiki/IconDock_En#iconDock_jQuery_Plugin

So … I read
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
and my question is: What are the odds that there will be a conflict?

How can I find out definitely if validates_captcha conflicts with
jQuery?

Posted viahttp://www.ruby-forum.com/.

Well if you’re observing validates_captcha acting odd when you’re
using jQuery, or vice-versa, you’ve found out…

Another easy way to avoid conflict between the various JS libraries is
to do something like this:

jQuery.noConflict();
(function($) {
… //jquery code goes here, allowing you to use $ willy-nilly…
})(jQuery);

you’ll need to make sure that the jQuery.noConflict() call comes
before any code using Prototype or whatever runs (as
validates_captcha uses the inline rjs helpers this shouldn’t be a
concern, but I’ve yet to actually use validates_captcha so you’ll
see)

Completely offtopic though, I find jQuery overwhelmingly useful and
intuitive. Granted, while its more just a “DOM manipulation, ajax and
effects” library where Prototype is a general purpose Javascript
framework, Javascript’s soo flexible and powerful that a library
adding class-based inheritance and enumerators everywhere often gets
in the way of the “Javascript-way” of doing things.