Search code examples
ruby-on-railsruby-on-rails-5

Rails inline javascript and turbolinks


I need to embed an external form in my app which uses the following code:

<script type="text/javascript" src="https://company.formsite.com/forms/js.php/form_name"></script>

Code is place in the a view and only loads once the page is refresh and not on the initial visit. I'm sure this has something to do with Turbolinks, but how do I resolve this with an external source?

I've looked into:

<script type="text/javascript" data-turbolinks-track="true" src="https://company.formsite.com/forms/js.php/form_name"></script>
<script type="text/javascript" data-turbolinks="false" src="https://company.formsite.com/forms/js.php/form_name"></script>

But have had no luck.


Solution

  • I ended up adding the following conditional to my header. Not sure if there is a better way, but it solved my issue for me.

    <head>
      <% if current_page?(controller: 'controller_name', action: 'page_name') %>
        <meta name="turbolinks-visit-control" content="reload">
      <% end %>
    </head>