【问题标题】:rails 4 how to configure ckeditor 4.1rails 4如何配置ckeditor 4.1
【发布时间】:2017-12-11 22:07:40
【问题描述】:

我不想在我的 Rails 应用程序中使用 CKEditor。

在我的 gemfile 中我添加了这一行

gem 'ckeditor', :git => 'https://github.com/galetahub/ckeditor.git'

在我运行“bundle update”和“rails generate ckeditor:install --orm=active_record --backend=paperclip”之后,我将这一行添加到我的 application.js:

//= require ckeditor/init

在我看来,我添加了这一行:

<%= f.cktext_area :img, :ckeditor => {:toolbar => 'img', :customConfig => asset_path('ckeditor/config.js')} %>

我创建了这些文件夹和文件:

/app/assets/javascripts/ckeditor
/app/assets/javascripts/ckeditor/config.js
/app/assets/javascripts/ckeditor/contents.css

我的 config.js 看起来像这样:

CKEDITOR.editorConfig = function( config )
{
    config.toolbar_img = [
        { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] },
    ]
}

为什么我的编辑器看起来像这样?

【问题讨论】:

  • 你期待它是什么?
  • 为什么它有这么多工具栏?我不想只有新页面和预览按钮:)
  • 您在 CKEditor 中的哪里看到“新页面”和“预览按钮”?您可以发布您在代码中添加的文档配置的链接吗?
  • 我编辑了上面的问题。现在我有了在这个页面上找到的这个工具栏:docs.ckeditor.com/#!/guide/dev_toolbar。结果是一样的。

标签: ruby-on-rails ruby ckeditor


【解决方案1】:

用这个改变你的 config.js 文件:

CKEDITOR.config.toolbar= [
    { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] }
];

确保您的 application.js 文件中需要 config.js:

//= require ckeditor/init
//= require_tree ./ckeditor

此外,CSS 文件应该在此处:/app/assets/stylesheets/ckeditor/contents.css 不在此处/app/assets/javascripts/ckeditor/contents.css

完成上述更改后,您可以:&lt;%= f.cktext_area :img %&gt;

但是,如果您想直接在 text_area 中传递配置值,那么应该这样做:

<%= f.cktext_area :img, :ckeditor => {:toolbar => 'mini'} %>

或:

<%= f.cktext_area :img, :ckeditor => {:toolbar => {'name' => 'document', 'items' => ['Source']} } %>

【讨论】:

  • 不,没用。我不明白,为什么我的代码加上你的添加不起作用。
  • 同样的事情对我有用。您是否删除了您拥有的其他代码?还要确保您在 application.js 中有所需的配置文件
  • 是的,我用你的代码更新了我的代码。老编辑器又来了。
  • 试一试:&lt;%= f.cktext_area :img %&gt; 不要提及所有自定义配置,因为您已经将它包含在 application.js 文件中。在浏览器上打开你的开发控制台并尝试:CKEDITOR.config.toolbar 看看它是否只返回一个对象。
  • 在我删除 :ckeditor => ... 编辑器显示正确。如何为不同的编辑器使用不同的配置?
【解决方案2】:

在视图中:

      <%= k.cktext_area :template_text, required: true, :class =>"emailBodyTemplate",  :id => "emailBodyText", placeholder: "Email Body Text", :maxlength => 255 %>

在 app/assets/javascripts/ckeditor/config.js 中:

  CKEDITOR.editorConfig = function (config) {
  config.toolbar_mini = [
    ["Bold",  "Italic",  "Underline",  "Strike",  "-"],
    ['BulletedList','NumberedList' ],['Outdent','Indent'],
   ];
  config.toolbar = "mini";
  config.toolbarLocation = 'bottom';
  config.height = 280;       
  config.width = 620;     
  config.removePlugins = 'elementspath';config.removePlugins = 'elementspath';
}

输出:

customized CKEditor

【讨论】:

  • 谢谢!但它来得太晚了 3 年:D
猜你喜欢
  • 2018-10-21
  • 1970-01-01
  • 2015-07-24
  • 2014-06-18
  • 1970-01-01
  • 2015-09-12
  • 2014-11-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多