Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Error in jQuery document ready handler in Rails 4 #26

Closed
nickurban opened this Issue · 7 comments

4 participants

@nickurban

This worked fine in Rails 3.2. I'm updating to Rails 4 and experiencing an error in my document ready handlers. If I remove jquery.turbolinks from my application.js, the error goes away.

behavior.js is a file with a declaration like this:

jQuery(function($) {
  $('form').submit(function(){
  ...
  });
});

On page load, I get the following error:

Uncaught TypeError: object is not a function behavior.js?body=1:2
(anonymous function) behavior.js?body=1:2
jQuery.event.dispatch jquery.js?body=1:5096
elemData.handle jquery.js?body=1:4767
jQuery.event.trigger jquery.js?body=1:5008
(anonymous function) jquery.js?body=1:5692
jQuery.extend.each jquery.js?body=1:658
jQuery.fn.jQuery.each jquery.js?body=1:267
jQuery.fn.extend.trigger jquery.js?body=1:5691
$.turbo.onLoad jquery.turbolinks.js?body=1:33
fire jquery.js?body=1:3049
self.fireWith jquery.js?body=1:3161
jQuery.extend.ready jquery.js?body=1:434
completed jquery.js?body=1:105
@nickurban

I downgraded to 1.0 and it's working again, so this seems like a 2.0 problem.

@rstacruz
Collaborator

Oh man, seems like jQuery(function($) { .. }) isn't working anymore as part of the move to use jQuery's own triggering mechanism for 2.0.

@rstacruz rstacruz closed this in 41953e7
@rstacruz
Collaborator

Just issued a fix. See if this helps—it should now work as expected.

For now, you'll need to upgrade to the latest unreleased version to try it out.

gem 'jquery-turbolinks', github: 'kossnocorp/jquery.turbolinks'
$ bundle update jquery-turbolinks
@nickurban

Thanks, that seems to work.

@rstacruz
Collaborator

@kossnocorp I've bumped to v2.0.1 (and even drafted a release in /releases) — feel free to rake release whenever :)

@kossnocorp
Owner

@rstacruz thanks!

Done.

@jxdx

That didn't work for me, still have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.