SammyLin / redactor-rails

This repo is deprecated. Please check out official gem for Redactor 2. https://github.com/Redactor2/redactor2_rails
MIT License
389 stars 253 forks source link

Conflict with TurboLinks #118

Closed jsandlund closed 9 years ago

jsandlund commented 10 years ago

Hi,

Redactor doesn't display on first page-load when turbolinks is active. Upon page load, it properly renders. Disabling turbolinks on the "body" element fixes this issue.

Thoughts on the root cause? Form code below.

<%= form_for @article do |f| %>

<div class="container">
    <div class="row">
        <div class="col-md-12">

            <% if @article.errors.any? %>
                <h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>     
                <ul>
                <% @article.errors.full_messages.each do |msg| %>
                    <li> <%= msg %></li>
                <% end %>
                </ul>   
            <% end %>
        </div>
    </div>
</div>

<p class="text-center">
    <%= f.label :title %><br>
  <%= f.text_field :title %>
</p>

<div class="container">
    <div class="row">
        <div class="redactor-box col-md-12">
          <%= f.text_area :text, :class =>"redactor" %>
        </div>
    </div>
</div>

<p>
    <%= f.label :featured %>?<br>
  <%= f.check_box :featured %> yes
</p>

<p><%= f.submit %></p>

<% end %>

Jellyfishboy commented 10 years ago

Hi jsandlund,

I came across this same issue earlier in my development. Due to the (odd) way Turbolinks works, you need to do two things in order for Redactor to load first time:

  1. Require the redactor asset files before the turbolinks asset
  2. Hook into the page:change and page:load calls and instantiate the redactor function

Here is an example: https://github.com/Jellyfishboy/trado/blob/master/app/assets/javascripts/administration.js.erb

Hope this helps! Tom

wilgoszpl commented 9 years ago

This issue is solved in new 0.5.0 version of redactor-rails.