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 254 forks source link

rails 4 + bootstrap + redactor error #73

Closed wangfuhai2013 closed 9 years ago

wangfuhai2013 commented 11 years ago

i use rails 4 + bootstrap + redactor in chrome ,the redactor 's toolbar can't displayed , must refresh browser, it displayed.

i call redactor in view to solve the above problem ,like this:

<script type="text/javascript">
    $(document).ready(
      function(){
      var csrf_token = $('meta[name=csrf-token]').attr('content');
      var csrf_param = $('meta[name=csrf-param]').attr('content');
      var params;
      if (csrf_param !== undefined && csrf_token !== undefined) {
        params = csrf_param + "=" + encodeURIComponent(csrf_token);
      }
      $('#redactor').redactor(
        { "imageUpload":"/redactor_rails/pictures?" + params,
          "imageGetJson":"/redactor_rails/pictures",
          "fileUpload":"/redactor_rails/documents?" + params,
          "fileGetJson":"/redactor_rails/documents",
          "path":"/assets/redactor-rails",
          "css":"style.css",
          "autoresize":"true"} 
      );
    });
  </script>
   <div class="field" >
    <%= f.label :data %>
    <%= f.text_area :data , :id=>"redactor",:rows => "15" %>
  </div>

it's ok, but when i add lang setting like this:

<script type="text/javascript">
    $(document).ready(
      function(){
      var csrf_token = $('meta[name=csrf-token]').attr('content');
      var csrf_param = $('meta[name=csrf-param]').attr('content');
      var params;
      if (csrf_param !== undefined && csrf_token !== undefined) {
        params = csrf_param + "=" + encodeURIComponent(csrf_token);
      }
      $('#redactor').redactor(
        { "imageUpload":"/redactor_rails/pictures?" + params,
          "imageGetJson":"/redactor_rails/pictures",
          "fileUpload":"/redactor_rails/documents?" + params,
          "fileGetJson":"/redactor_rails/documents",
          "path":"/assets/redactor-rails",
          "css":"style.css",
          "autoresize":"true",
         "lang" : "zh_cn"} 
      );
    });
  </script>
 <%= redactor_lang('zh_cn') %>

i got a error in chrome :

Uncaught TypeError: Cannot read property 'html' of undefined
c.fn.d.Redactor.initToolbar
c.fn.d.Redactor.buildAfter
c.fn.d.Redactor.buildStart
c.fn.d.Redactor.init
c
(anonymous function)
jQuery.extend.each jquery.js:658
jQuery.fn.jQuery.each jquery.js:267
d.fn.redactor
(anonymous function) new:10
fire jquery.js:3049
self.add jquery.js:3095
jQuery.fn.jQuery.ready jquery.js:272
(anonymous function) new:2
executeScriptTags turbolinks.js:136
changePage turbolinks.js:113
xhr.onload

my gem file version: redactor-rails 0.3.5 twitter-bootstrap-rails 2.2.7

DaviMedrade commented 10 years ago

I have the same error, with gem version 0.4.

From what I could gather, the language files need to be updated, since apparently the way Redactor initializes the languages has changed.

I was able to work around this issue by inserting this line in config.js:

...
$.Redactor.opts.langs['pt_br'] = RELANG['pt_br'];
$('.redactor').redactor(
...
SammyLin commented 10 years ago

hi @wangfuhai2013 fix bug f764fb4af197ab3524c694d8a389cff4d5c2f740

you can use update version 0.4.1

and

Add to your application.js:

//= require redactor-rails/langs/zh_cn

so your can remove

$.Redactor.opts.langs['zh_cn'] = RELANG['zh_cn'];
marslo commented 10 years ago

Please update zh_cn.js file:

header4: '四级标题',
header5: '五级标题'
bold:  '粗体',

There is a comma missing at the header5 line!!

wilgoszpl commented 9 years ago

@Marslo language files are updated now. Thanks for @davidsantos-br for taking care of this