如何在 Rails 3.1 资产管道中编译和加载 ckeditor 资源
我正在尝试在 Rails 3.1 应用程序中使用 CKEditor。我的 ckeditor 目录位于 app/assets/javascripts/ckeditor/ 中,其中删除了诸如未压缩和模块化源代码之类的无关内容。
它在开发中工作得很好。在生产或登台环境中,ckeditor找不到自己的文件:config.js、lang/en.js Skins/kama/editor.css。我可以看到这些文件没有被预编译,这是有道理的,因为默认情况下资源管道不会包含或预编译任何与 /.css/ 或 /.js/ 匹配的内容。
根据 Rails 文档和以前的答案,例如这个,将我需要的文件添加到 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 asset:precompile 仍然无法将我需要的文件移动到 public/assets 中。所有图像等都可以,但 CKEditor 需要运行的三个 javascript 和/或 css 文件除外。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也遇到过类似的问题。我最终使用了没有资产管道的 CKEditor :)
在尝试了几个 gem 后,没有一个在生产环境中正常工作。我最终将 ckeditor 放入应用程序的
public
文件夹中。这完全跳过了资产管道过程,并且 ckeditor 在生产中也运行得很好。不过没有资产预编译...使用rails 3.1,CKEditor 4.1。虽然这是一个旧线程,但也许这可以帮助某人...
更新:此外,如果您在本地生产环境中进行测试,请不要忘记在
中将
serve_static_assets
设置为 true配置/环境/生产.rbI've run into similar issues. I ended up using CKEditor without asset pipeline :)
After several gems tried, none worked ok in production environment. I ended up putting ckeditor into
public
folder of the app. That skips the asset pipeline process completely and ckeditor works just fine in production as well. No assets pre-compilation though...Using rails 3.1, CKEditor 4.1. Although this is an old thread, maybe this could help someone...
Update: Also, if you're testing on your local production environment, don't forget to set
serve_static_assets
to true inconfig/environments/production.rb
对我来说,它是通过覆盖默认预编译任务来修复的(我使用 Rails 4 和 CkEditor 4)。
config.assets.precompile += ['ckeditor/*']
//= require ckeditor/init
lib /tasks/precompile_hook.rake
并粘贴此答案中的文本 预编译钩子For me it was fixed by overriding default precompile task (I used Rails 4 and CkEditor 4).
config.assets.precompile += ['ckeditor/*']
//= require ckeditor/init
lib/tasks/precompile_hook.rake
and paste text from this answer Precompile hook您的代码中有语法错误。预编译属性是一个数组。
您可以将单个项目附加到数组中,如下所示:
如果您的值位于数组中,则必须添加该数组。
如果追加,则会在预编译数组中嵌套一个数组,该数组将被忽略。
You have a syntax error in your code. The precompile attribute is an array.
You can append a single item to the array like this:
If your values are in an array then you have to ADD the array.
If you append then you'd have an array nested inside the precompile array, which is ignored.