Ruby on Rails 3.1,Ckeditor自定义工具栏.在哪里定义

Mat*_*ing 6 ruby-on-rails ckeditor ruby-on-rails-3

我用gem来安装ckeditor.因此,项目中没有config.js(实际的gem文件夹中有我不想修改).安装确实在config/initializers文件夹中创建了一个ckeditor.js,它似乎是放置工具栏定义的正确位置.但是我试图让它工作的所有内容都会引发各种语法或方法未找到的错误.有人有这个成功吗?如果是这样,一个快速的例子会非常有帮助.

我目前的ckeditor.js是:

# Use this hook to configure ckeditor
if Object.const_defined?("Ckeditor")
  Ckeditor.setup do |config|

  # ==> ORM configuration
  # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
  # available as additional gems.
  require "ckeditor/orm/active_record"

  # Allowed image file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.image_file_types = ["jpg", "jpeg", "png", "gif", "tiff"]

  # Allowed attachment file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.attachment_file_types = ["doc", "docx", "xls", "odt", "ods", "pdf", "rar", "zip", "tar", "swf"]
  end
end
Run Code Online (Sandbox Code Playgroud)

田咖啡*_*田咖啡 5

1.在application.js中添加以下内容

//= require ckeditor/ckeditor
//= require_tree ./ckeditor
Run Code Online (Sandbox Code Playgroud)

2.在app/assets/javascript/ckeditor中添加config.js示例config.js

if(typeof(CKEDITOR) != 'undefined')
{
 CKEDITOR.editorConfig = function(config) {
   config.uiColor = "#AADC6E";
   config.toolbar = [
    [ 'Bold', 'Italic', 'Underline', 'Strike' ],
    [ 'NumberedList', 'BulletedList', 'HorizontalRule' ],
    [ 'Blockquote' ],
    [ 'Undo', 'Redo' ],
    [ 'insertResolved' ],
    [ 'Source' ]
 ];
}
} else{
  console.log("ckeditor not loaded")
}
Run Code Online (Sandbox Code Playgroud)


小智 3

我有和你一样的问题。起初,我遵循资产管道的配置轨道,但它对我不起作用。然后我意识到该链接的作者只是创建了一种新样式的工具栏。您还需要在视图中调用它。这意味着你需要添加这一行

input_html => {:toolbar => 'MyToolbar'}
Run Code Online (Sandbox Code Playgroud)

使其发挥作用。

为了测试config.js是否正常工作,您可以检查网页的源代码,看看是否添加了assets/javascripts/ckeditor/config.js。另一种检查方法是通过取消注释此行来编辑编辑器颜色:config.uiColor = '#AADC6E'。如果编辑器的颜色发生变化,那么它就可以工作。

我还犯了一个愚蠢的错误,我将 ckeditor js 文件包含两次:一次在 application.js 中,一次在 layouts/application.html.haml 文件中。不知道这是否是问题的根源。你可以试试。

希望这可以帮助。