jquery-mobileruby-on-rails-4.1

jQuery Mobile on Ruby on Rails 4 Returning Blank Pages


For some reason, jQuery Mobile is returning blank pages sometimes when I use the back/forward button on my web browser.

So I searched around and a lot of people say to turn off AJAX, and your back/forward buttons will work better.

So I added the following code to my program:

$(document).bind("mobileinit", function(){
    $.mobile.ajaxEnabled = false;
});

This way, each web page loads in its own URL.

So I put this in, but some pages still give me a blank page when I click on the link.

The URL hits the browser, so I know AJAX is disabled.

Pressing "Refresh" on the browser loads the page properly.

Perhaps there is a conflict with the Rails Turbolinks? That's the only idea I can muster for the cause of the problem.

I am using jQuery 1.4.5 on Ruby on Rails 4.1.7.


Solution

  • I figured out the solution to the problem. In rails 4, when you load jquery, you have to add the gem "jquery-turbolinks" to your Gemfile. Then load:

    //= require jquery.turbolinks
    

    in your application.js file. This line has to come AFTER "//= require jquery" and BEFORE "//= require turbolinks". After that, jquery-mobile works fine in rails 4