ckeditor gem custom config.js 未在生产中加载
Posted
技术标签:
【中文标题】ckeditor gem custom config.js 未在生产中加载【英文标题】:ckeditor gem custom config.js not loading in production 【发布时间】:2019-03-20 03:05:04 【问题描述】:我按照 gem 自述文件中的说明在我的 rails 应用程序上使用 ckeditor,但是一旦我尝试在带有 heroku 的生产环境中使用它,使用的 config.js 文件来自 CDN 链接,而不是来自我的资产/javascripts/ckeditor/config.js 文件。自定义配置在开发环境中工作。
ckeditor.rb 初始化程序/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 )
初始化程序/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】:首先你应该在ckeditor.rb
中为config.js
设置正确的路径:
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)
【讨论】:
谢谢。我尝试了您的建议,它仍然使用 CDN“//cdn.ckeditor.com/4.11.3/standard/ckeditor.js”中的 config.js 文件。我还尝试了“/assets/javascripts/ckeditor/config.js”,但在生产应用程序中仍然没有任何变化。 你使用的是什么版本的 Rails? 我使用的是 Rails 5.1.6。 你能分享所有 assets.rb 吗? 删除这一行:config.cdn_url = "//cdn.ckeditor.com/4.11.3/standard/ckeditor.js"
以上是关于ckeditor gem custom config.js 未在生产中加载的主要内容,如果未能解决你的问题,请参考以下文章
ruby 使用SendWithUs和Custom Devise Mailer以及sendwithus_ruby gem