How do I use Turbolinks and local_time together? - ruby-on-rails

I've noticed recently, probably since installing Rails 5 that the local_time gem doesn't work properly on pages where the link was internal (through turbolinks). If the link to the page was external or the browser refreshed, or turbolinks is disabled, local_time works properly.
Does anyone know how to use these together?

I needed to initialize the local time on TurboLinks load. This event provides a chance to do those things that would have run at document ready. The JavaScript is:
document.addEventListener("turbolinks:load", function() {
LocalTime.run();
});

Related

Rails 5 Turbolinks appears to reload page

I am still new to Turbolinks and unsure whether it is working correctly. I have a new rails app that I've created with Turbolinks enabled by default. I am using the link_to rails helper to build some links. When I click on one of the links the page reloads in the browser. I was under the impression that this should not occur as only the body should be swapped using AJAX. Is there any additional attributes I need to add to my link or additional configuration I need to set up?
Make sure that you have the Turbolinks js loaded in the page. If you are using webpacker and removed the default application js that used the asset pipeline you will probably need to use Turbolinks from npm, import it and then call Turbolinks.start() in your entry file.

many turbolinks when I browser back

I am developing in Ruby on Rails.
I get many turbolinks when I use browser back like this.
have many turbolinks linke this
Although I move page by clicking a tag, I have no turbolinks.
Only I use browser back, I have many turbolinks loading and reload webpage many times.
How can I browser back smoothly just like I click a tag.
SO! not clear your question, for suggestion if you do not need turbolinks on your application then remove the gem 'turbolinks' from Gemfile update the bundle and remove //= require turbolinks this line from assets/application.js and finally restart the server.
Number 2
If need to disable turbolinks for specific link then use data-turbolinks="false" for this link which you need to not use turbolinks like below
Disabled
See more about turbolinks on there documentation
Hope it helps

why do i remove turbolinks before using angular

gem install rails -v 4.1
rails new angular_example
Before using angular i'm recommended to remove turbolinks.
So why do i have to remove it and what's the purpose of turbolinks?
Because Angular and Turbolinks can conflict with one another,angular doesn't work correctly. So we disable turbolinks.
Turbolinks handle the request made by browser. For example AJAX request to the server, waiting the answer, deleting the old content and replacing it with the new content

Turning on turbolink

After I've precompiled assets and uploaded them to CDN I decided to turn on turbolinks. They were kind of turned on before when I were precompiling assets, that is I had gem turbolinks in Gemfile and require turbolinks in application.js but in application.html I had data-no-turbolink instead of data-turbolinks-track" => true.
Now I change it to data-no-turbolink to data-turbolinks-track" => true and expect them to work in production on the my local machine but it seems they aren't. Visually it seems they aren't working and "initiator" in the browser isn't turbolinks.
I don't want to recompile the assets if it's not really needed because reuploading them to CDN takes a lot of time.
So do I have to recompile them? Or perhaps I just don't notice that they are really working already?
data-turbolinks-track is only for asset tracking (to make sure the loaded assets file is the latest). It does not affect whether Turbolinks is used for a particular link.
If turbolinks is installed, any internal link without data-no-turbolink will be loaded using Turbolinks UJS.
The following code will fire an alert if Turbolinks is running.
$(document).on('page:load', function(){ alert("Turbolinks is active"); });
Not easy with the sparse information you provide. But here are some notes worth considering:
About Turbolinks:
With Turbolinks pages will change without a full reload, so you can't
rely on DOMContentLoaded or jQuery.ready() to trigger your code.
Instead Turbolinks fires events on document to provide hooks into the
lifecycle of the page.
You probably use jQuery? Read above link to understand. A good solution is this one: jQuery.turbolinks
...
But if you have a large codebase with lots of $(el).bind(...)
Turbolinks will surprise you. Most part of your JavaScripts will stop
working in usual way. It's because the nodes on which you bind events
no longer exist.
...

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.
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

Resources