thiebo
thiebo

Reputation: 1435

javascript only works on page reload (rails, turbolinks installed)

I have this link

<%= link_to "contact", ecrire_message_path %> 

That page contains:

$(document).on('turbolinks:load', function(){
    // some correct javascript here
});

The javascript doesn't work when I click on the link. It only works after page reloads.

turbolink gem is installed and included.

I don't know how to add to the link_to element not to use turbolinks.

Thanks

Upvotes: 1

Views: 797

Answers (1)

mechnicov
mechnicov

Reputation: 15248

You can use

<%= link_to "contact", ecrire_message_path, data: { turbolinks: false } %>

From official guide:

If you want to disable Turbolinks for certain links, add a data-turbolinks="false" attribute to the tag:

<a href="..." data-turbolinks="false">No turbolinks here</a>

Upvotes: 3

Related Questions