javascriptruby-on-railsrubyturbolinks

Rails 4: disable Turbolinks in a specific page


I'm trying to make a JS snippet work in a concrete page with Rails 4 and Turbolinks. I've tried with the standard solution:

<script type="text/javascript">

    var ready = function() {
        // Bla bla
    };

    $(document).ready(ready);
    $(document).on('page:load', ready);
</script>

But it doesn't seem to work. My snippet is something like this:

<script type="text/javascript">
  function ismready() 
  {
    var API_KEY = "api key";
    var roomId  = "room id";
    var ism = new Ismuser(API_KEY, roomId);
    ism.init({
      board: {
        layer: "board"
      },
      video: {
        camsContainer: "guest"
      },
      chat: {
        layer: "chat"
      },
      moderator: true,
    });
  }
</script>
<script src="http://assets.ismuser.com/v0.4/js/ismuser.js" type="text/javascript"></script>

The snippet doesn't work as expected (even with the standard solution) and finally I just want to disable Turbolinks in this page.

How can i do it?

-- Solution

<% content_for :body do %>
    <% if controller.controller_name == 'home' && controller.action_name == 'demo1' %>
        <body data-no-turbolink="true">
    <% end %>
<% end %>

Solution

  • Add “data-no-turbolink” to the <body> tag of the the page you want it disabled on

    If you have a shared layout file which i am assuming you do, you can do an if statement and check the params[:controller] and params[:action] and just add it to the one area

    Edited Jan 2021: As pointed out by @weltschmerz under rails 5 data-turbolinks="false" is the preference.