Rails does not load page for the first time - ruby-on-rails

When I press for example a link it redirects to this URL, but does not open full. It loads(loader gif moves). But when I press reload again - it loads. What is a problem? Can anyone saw such thing? How can I fix it?

Open Developer Tools in your browser and look at section of loading resources. For example here is Network Monitor of Firefox. It help you to investigate reason of problem. Probably some third-party resources isn't loading.

As mentioned by #maxd, use the Network Monitor in Firefox or Chrome Dev Tools to investigate further.
It sounds like the issue could be caused by the turbolinks gem conflicting with jQuery. Try removing turbolinks and restarting your local server to see if the problem persists.
Remove the following lines:
Gemfile: gem 'turbolinks'
application.js: //= require turbolinks
application.html.erb: "data-turbolinks-track => true"
Alternatively, if you want to use turbolinks, you can implement the jquery-turbolinks gem into your app.

Related

How to completely remove all of turbolinks from a Rails 5 project

I've read through the other available questions and answers and they don't solve my issue. I recently looked to remove turbolinks from my project because I was having problems setting up event listeners. Suggestions for modifying the jquery to use the turbolinks equivalents weren't working, so I decided to remove it entirely for now to unblock myself.
I've done the following:
Remove the gem from Gemfile
Bundle (confirmed in the bundle turbolinks is no longer listed)
Removed turbolinks attributes from links in the head
Removed the require from the application JS
Restored my JS file to the original jQuery implementation
However, the problem persists on production (Heroku). Everything continues to work locally. I was inspecting the source assets on production and noticed I can find traces of turbolinks in the compiled js file. I don't know if this is causing the problem and I don't know where it's coming from so I haven't been able to remove it to test.
My JS file is set up like so:
$(document).ready(function() {
console.log('Listener setup working...');
....
Any ideas greatly appreciated.

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

How do I use Turbolinks and local_time together?

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();
});

Content not being showed correctly

I do not know what is going on with my application. I already cleared server cache, browser cache, I think I already cleared all the cache possible.
I am running my ruby on rails application in linux distribution, but the content not always appears correctly. For instance, I go to the page and I see this:
Basically it does not care about some of the page information like if user is logged in or not. But if I click F5 to refresh the page it shows up correctly:
Any idea what is going wrong?
Possible this error is connected with js libraries, that you use. If you want simple solution, you can try remove turoblinks, but this can make your app slow.
if you can remove turoblinks:
Remove the gem 'turbolinks' line from your Gemfile.
Remove the //= require turbolinks from your
app/assets/javascripts/application.js.
Remove the two "data-turbolinks-track" => true
from your app/views/layouts/application.html.erb.

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

Resources