ckeditor gem自定义config.js未在生产中加载

时间:2019-03-20 03:05:04

标签: javascript ruby-on-rails rubygems ckeditor

我按照gem自述文件上的说明在我的rails应用程序上使用ckeditor,但是一旦我尝试在生产环境中将其与heroku一起使用,则使用的config.js文件来自CDN链接,而不是我的资产/javascripts/ckeditor/config.js文件。自定义配置可在开发环境中使用。

ckeditor.rb initializers / assets / application.rb

Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( ckeditor/*)
Rails.application.config.assets.precompile += %w( custom_styling.css )

initializers / assets / ckeditor.rb

    Ckeditor.setup do |config|
      require 'ckeditor/orm/active_record'

       config.image_file_types = %w(jpg jpeg png gif tiff)

       config.attachment_file_types = %w(mp4 doc docx xls odt ods pdf rar zip tar tar.gz swf)

       config.cdn_url = "//cdn.ckeditor.com/4.11.3/standard/ckeditor.js"

       config.js_config_url = 'ckeditor/config.js'
    end

assets / javascripts / ckeditor / config.js

    CKEDITOR.editorConfig = function( config ) {
      config.language = 'en';
      config.uiColor = '#ffffff';

      config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
      config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
      config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
      config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
      config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
      config.filebrowserImageUploadUrl = "/ckeditor/pictures?";
      config.filebrowserUploadUrl = "/ckeditor/attachment_files";
      config.allowedContent = true;

      config.toolbar = [
        { name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source'] },
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
        { name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
        { name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar' ] },

      ];
    };

config / initializers / assets.rb

Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( ckeditor/config.js)
Rails.application.config.assets.precompile += %w( custom_styling.css )

views / article_templates / edit_form.html.erb

<%= javascript_include_tag Ckeditor.cdn_url %>
<textarea id="content" name="content" class="ckeditor"><%= raw @article.content %></textarea>

1 个答案:

答案 0 :(得分:0)

首先,您应该在config.js中为ckeditor.rb设置正确的路径:

config.js_config_url = "/assets/ckeditor/config.js"

但是没有用,因为它是默认路径

  # JS config url
  # Used when CKEditor CDN enabled
  # By default: "/assets/ckeditor/config.js"
  # config.js_config_url = "/assets/ckeditor/config.js"

此外,您还应该通过以下方式更改资产的预编译:

Rails.application.config.assets.precompile += %w(ckeditor/config.js)