Search code examples
javascriptjqueryruby-on-railstinymceturbolinks

TinyMCE - have to refresh the page


When I navigate to a page with TinyMCE it displays regular textareas until I refresh the page because of turbolinks. This is a pretty well-documented issue and people generally recommend some form of the following:

$(document).on('page:change', function () {
    <code here>
}); 

I've tried every variation on this to no avail.


Solution

  • The problem was that a lot of the discussion around this issue is quite outdated and doesn't take into account that turbolinks events have changed as of 5.0.0.

    I was able to solve the problem with the following:

    $(document).on('turbolinks:load', function () {
       tinymce.remove();
       tinymce.init({selector:'.tinymce'});
    });
    

    A full list of turbolinks events can be found here