如何获取ckeditor资源来编译和加载在Rails 3.1资产管道 [英] How to get ckeditor resources to compile and load in Rails 3.1 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']
我已尝试添加匹配文件的正则表达式:
config.assets.precompile< [/.*config\.js/,/.*en.js/,/.*editor.css/]
我已尝试明确添加完整路径:
config.assets .precompile<< File.join(Rails.root,'app','assets','javascripts','ckeditor','config.js')
(etc ...)
在所有这些情况下(和我试过的一切),运行rake assets:precompile仍然无法将我需要的文件移动到公共/资产。所有的图像和这样去,但不是CKEditor需要运行的三个javascript和/或css文件。
任何想法?
- 添加到application.rb
config.assets.precompile + = ['ckeditor / *']
- 在application.js
// = require ckeditor / init
- 创建文件
lib / tasks / precompile_hook.rake
并粘贴此答案的文本预编译钩子
I'm trying to use CKEditor in a Rails 3.1 app. I have the ckeditor directory in app/assets/javascripts/ckeditor/, with extraneous stuff like the uncompressed and modularized source removed.
It works fine in development. In production or staging environments, ckeditor can't find it's own files: config.js, lang/en.js skins/kama/editor.css. I can see that these files are not being precompiled, which makes sense since the asset pipeline by default won't include or precompile anything that matches /.css/ or /.js/.
According to the rails docs and previous answers like this one, adding the files I need to config.assets.precompile is supposed to be the solution. However, despite extensive effort I cannot figure out what format I am supposed to use with config.assets.precompile. It's not documented and no examples are given.
I've tried explicitly adding the files by name:
config.assets.precompile << ['config.js', 'en.js', 'editor.css']
I've tried adding regexes that will match the files:
config.assets.precompile << [ /.*config\.js/, /.*en.js/, /.*editor.css/ ]
I've tried explicitly adding the full paths:
config.assets.precompile << File.join(Rails.root, 'app', 'assets', 'javascripts', 'ckeditor', 'config.js')
(etc...)
In all of these cases (and everything else I've tried), running rake assets:precompile still fails to move the files I need into public/assets. All the images and such go, but not the three javascript and/or css files CKEditor needs to run.
Any thoughts?
For me it was fixed by overriding default precompile task (I used Rails 4 and CkEditor 4).
- Add to application.rb
config.assets.precompile += ['ckeditor/*']
- In application.js
//= require ckeditor/init
- Create file
lib/tasks/precompile_hook.rake
and paste text from this answer Precompile hook
这篇关于如何获取ckeditor资源来编译和加载在Rails 3.1资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!