How to disable Turbolinks in a specific page?

前端 未结 6 1754
醉酒成梦
醉酒成梦 2021-02-12 13:54

I have an issue with a script only working when refreshing the page and so I\'m trying to disable Turbolinks for only that page. The code below doesn\'t work. However, if I add

6条回答
  •  不要未来只要你来
    2021-02-12 14:34

    You can use this oneliner in your layout:

    >
    

    But the other way to do it, which I use mostly, would be to put this chunk of code to the links leading to this page...

    So, let's suppose your route is named :policy, you should do this:

    <%= link_to "Policy", policy_path, :"data-no-turbolink" => true %>
    

    Long time has gone, here is an update

    Recently, I have started using turbolinks 5.0 beta, by:

    gem 'turbolinks', '~> 5.0.0.beta'
    

    It gets far easier... All document ready javascript gets loaded, no problem... All you have to do is add a listener to the load event.

    $(document).on('turbolinks:load', named_function );
    var named_function = function() {
        // thinks to do on document load
    }
    

    You don't have to also add

    $(document).ready(function (){
         // stuff
    });
    

    or

    $(document).ready(named_function);
    

    Because Turbolinks will gracefully fall back to document load if the page is hard loaded.

提交回复
热议问题