Answer the question
In order to leave comments, you need to log in
What is the correct way to use turbolinks in rails?
Good afternoon. Rails 4.2.5. I'm struggling with turbolink. Tell me how to correctly connect third-party JS scripts or call a function in application.js so that it runs once, when the page is fully loaded.
For example, in the footer, I throw a dialer service that runs twice:
<script type="text/javascript" src="//cdn.dozvonзкшьук.com/widget/js/dzv.js?przv_code=8355e"></script>
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require turbolinks
//= require_tree .
$(document).on('page:change', function() {
console.log('Выполняется один раз при полной загрузке страницы, а не два как сейчас при работе турболинка');
});
Answer the question
In order to leave comments, you need to log in
A great idea for solving turbolink problems is to demolish it immediately when creating a project.
Well, this is my IMHO;)
PS https://github.com/turbolinks/turbolinks-classic#events
I make a function and pass it to $(document).ready(...) and $(document).on('page:load', ...)
ready_service = function() {
return $('#start_registration_link'). on('click', function(event) {
return $('#registration-block').addClass('fullscreen');
});
};
$(document).ready(ready_service);
$(document).on('page:load', ready_service);
here is more details - https://habrahabr.ru/post/167161/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question