【发布时间】:2017-02-11 07:47:32
【问题描述】:
我在我的 Rails 应用程序中使用了ckeditor ruby gem (v4.2.2),它在开发中运行良好,但在我的production 环境中却不行。我的资产管道看起来没有问题,因为所有其他资产加载时都没有任何问题。
在页面上,谷歌浏览器给了我这个错误:
Uncaught TypeError: Cannot set property 'dir' of undefined
而 Firefox 只是在控制台中抛出这个:
TypeError: c[a] is undefined[Learn More]
到目前为止我所做的尝试:
- 在 Sprockets 中使用
Uglifier.new(mangle: false)作为 JS 压缩器 - 手动设置
CKEDITOR_BASEPATH
rake asset:precompile在public/assets/ckeditor中生成的asset文件都有一个hash,如下:
ckeditor-e0b9bfe15298d2b2dd388960b27d35e6a18c89b2390f8986d398c30da5496e4b.js
config-1fb318e1cc0eea7b8c181941c3c1f09d2b96107b2f7ff4891755fbb2201ba53d.js
contents-4540cf2cb7116b32bac2995494c4fc0c55804444f37c02cfa11256bd695e4194.css
# etc
但 JS 似乎没有加载它们并尝试现在修复它。
代码
我的 Javascript 文件:
//= require pages-javascript
//= require ckeditor/init
//= require_tree ./ckeditor
//= require_self
资产初始化器:
# config/initializers/assets.rb
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile << Proc.new do |filename, full_path|
if filename =~ /\.(css|js|svg|eot|woff|ttf)\z/
app_assets_path = Rails.root.join('app', 'assets').to_s
if full_path.starts_with? app_assets_path
Rails.logger.info "including asset: " + full_path
true
else
Rails.logger.info "excluding asset: " + full_path
false
end
else
false
end
end
Rails.application.config.assets.precompile += %w( ckeditor/* )
【问题讨论】:
-
我看到你专门为 ckeditor 准备了一个清单文件,对吧?
标签: ruby-on-rails ckeditor sprockets uglifier