Tom
Tom

Reputation: 9653

Rails: error with pjax "Uncaught TypeError: Object [object Object] has no method 'pjax' "

Gemfile:

gem 'pjax_rails'

app/assests/javascripts/application.js :

//= require jquery 
//= require jquery_ujs 
//= require_tree . 
//= require jquery.pjax


$(function() {
 $('a').pjax('[data-pjax-container]');
});

app/views/layouts/application.html.erb:

<div id="data-pjax-container" data-pjax-container>
        <%= yield %>
</div>

The error i'm getting in chrome is:

Uncaught TypeError: Object [object Object] has no method 'pjax'

And it refers to the application.js file. What is wrong here?

Upvotes: 0

Views: 748

Answers (1)

caarlos0
caarlos0

Reputation: 20633

I think you could change you imports to:

//= require jquery 
//= require jquery_ujs 
//= require jquery.pjax
//= require_tree . 

I also do believe that you should bind it in your ready event, like this:

$(document).ready(function() {
 $('a').pjax('[data-pjax-container]');
});

Hope it helps

Upvotes: 1

Related Questions