7

我使用 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
4

5 回答 5

5

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

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

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")
}
于 2014-01-13T02:32:43.317 回答
3

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

input_html => {:toolbar => 'MyToolbar'}

让它工作。

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

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

希望这可以帮助。

于 2012-05-21T09:38:02.467 回答
1

这对我有用: How to configure CKEditor in Rails 3.1 (gem + Asset Pipeline) 只需将答案中给出的片段保存在 config.js 文件中

于 2012-04-27T08:54:15.270 回答
1

可能是我对 github 的评论会帮助你https://github.com/galetahub/ckeditor/issues/136#issuecomment-8870692

于 2012-09-26T01:20:20.060 回答
0

这是使用ckeditor 4.1.0自定义配置 ckeditor 工具栏的Rails 4.1的更新答案。

在您看来,使用 simple_form,您需要像以下示例一样配置输入:

_FORM.HTML.ERB

<%= simple_form_for(@foo) do |f| %>
  <%= f.input :bar, as: :ckeditor %>
  <%= f.button :submit %>
<% end %>

在您的 Javascript 资产中,您需要创建一个名为“ckeditor”的文件夹,并在其中创建一个名为“config.js”的文件

../JAVASCRIPTS/CKEDITOR/CONFIG.JS

CKEDITOR.editorConfig = function(config) {
  //config.language = 'es'; //this could be any language
  config.width = '725';
  config.height = '600';

  // Filebrowser routes
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed.
  config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
  config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
  // The location of a script that handles file uploads in the Flash dialog.
  config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
  config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
  config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
  // The location of a script that handles file uploads in the Image dialog.
  config.filebrowserImageUploadUrl = "/ckeditor/pictures";
  // The location of a script that handles file uploads.
  config.filebrowserUploadUrl = "/ckeditor/attachment_files";

// You could delete or reorder any of this elements as you wish
  config.toolbar_Menu = [
    { name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'] }, 
    { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, 
    { name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'] }, 
    { name: 'tools', items: ['Maximize', 'ShowBlocks', '-', 'About'] }, '/', 
    { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] }, 
    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] }, 
    { name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, '/', 
    { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] }, 
    { name: 'colors', items: ['TextColor', 'BGColor'] }, 
    { name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'] }
  ];
  config.toolbar = 'Menu';
  return true;
};

application.js 的配置是这样的,注意 ckeditor 和 require_tree 的顺序很重要

应用程序.JS

//= require jquery
//= require jquery_ujs
//= require ckeditor/init
//= require_tree .

现在在您的 ckeditor.rb 中,您应该取消注释“config.asset_path”这一行并将路径添加到您之前创建的 config.js 文件中,即“/assets/ckeditor/”

../CONFIG/INITIALIZERS/CKEDITOR.RB

# Use this hook to configure 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"

  # Customize ckeditor assets path
  # By default: nil
  config.asset_path = "/assets/ckeditor/"
end

我希望它有所帮助:D!

于 2014-11-08T08:35:26.143 回答