Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Error in jQuery document ready handler in Rails 4 #26

Closed
nickurban opened this issue Aug 21, 2013 · 7 comments
Closed

Error in jQuery document ready handler in Rails 4 #26

nickurban opened this issue Aug 21, 2013 · 7 comments

Comments

@nickurban
Copy link

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
Copy link
Author

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

@rstacruz
Copy link
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
Copy link
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
Copy link
Author

Thanks, that seems to work.

@rstacruz
Copy link
Collaborator

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

@kossnocorp
Copy link
Owner

@rstacruz thanks!

Done.

@jxdx
Copy link

jxdx commented May 16, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants