Ida*_*oEv 5 ruby-on-rails ckeditor ruby-on-rails-3 asset-pipeline
我正在尝试在Rails 3.1应用程序中使用CKEditor.我在app/assets/javascripts/ckeditor /中有ckeditor目录,删除了未压缩和模块化的源等无关的东西.
它在开发中工作正常.在生产或登台环境中,ckeditor找不到它自己的文件:config.js,lang/en.js skins/kama/editor.css.我可以看到这些文件没有被预编译,这是有道理的,因为默认情况下资产管道不会包含或预编译与/.css/或/.js/匹配的任何内容.
根据rails docs和之前的答案,如下所示,添加config.assets.precompile所需的文件应该是解决方案.然而,尽管付出了大量的努力,我无法弄清楚我应该使用config.assets.precompile的格式.它没有记录,也没有给出任何例子.
我试过按名称显式添加文件:
config.assets.precompile << ['config.js', 'en.js', 'editor.css']
Run Code Online (Sandbox Code Playgroud)
我尝试添加与文件匹配的正则表达式:
config.assets.precompile << [ /.*config\.js/, /.*en.js/, /.*editor.css/ ]
Run Code Online (Sandbox Code Playgroud)
我试过明确添加完整路径:
config.assets.precompile << File.join(Rails.root, 'app', 'assets', 'javascripts', 'ckeditor', 'config.js')
(etc...)
Run Code Online (Sandbox Code Playgroud)
在所有这些情况下(以及我尝试过的所有其他情况),运行rake资产:预编译仍然无法将我需要的文件移动到公共/资产中.所有图像都是如此,但不是CKEditor需要运行的三个javascript和/或css文件.
有什么想法吗?
您的代码中有语法错误。预编译属性是一个数组。
您可以将单个项目附加到数组中,如下所示:
config.assets.precompile << 'name_of_file.ext'
Run Code Online (Sandbox Code Playgroud)
如果您的值在数组中,那么您必须添加该数组。
config.assets.precompile += [ /.*config\.js/, /.*en.js/, /.*editor.css/ ]
Run Code Online (Sandbox Code Playgroud)
如果追加,则会在预编译数组中嵌套一个数组,该数组将被忽略。