如何在 Rails 3.1 资产管道中编译和加载 ckeditor 资源

发布于 2024-12-29 02:43:02 字数 1164 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

许一世地老天荒 2025-01-05 02:43:02

我也遇到过类似的问题。我最终使用了没有资产管道的 CKEditor :)

在尝试了几个 gem 后,没有一个在生产环境中正常工作。我最终将 ckeditor 放入应用程序的 public 文件夹中。这完全跳过了资产管道过程,并且 ckeditor 在生产中也运行得很好。不过没有资产预编译...

使用rails 3.1,CKEditor 4.1。虽然这是一个旧线程,但也许这可以帮助某人...

更新:此外,如果您在本地生产环境中进行测试,请不要忘记在 中将 serve_static_assets 设置为 true配置/环境/生产.rb

I'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 in config/environments/production.rb

蓝咒 2025-01-05 02:43:02

对我来说,它是通过覆盖默认预编译任务来修复的(我使用 Rails 4 和 CkEditor 4)。

  1. 添加到 application.rb config.assets.precompile += ['ckeditor/*']
  2. 在 application.js //= require ckeditor/init
  3. 创建文件 lib /tasks/precompile_hook.rake 并粘贴此答案中的文本 预编译钩子

For me it was fixed by overriding default precompile task (I used Rails 4 and CkEditor 4).

  1. Add to application.rb config.assets.precompile += ['ckeditor/*']
  2. In application.js //= require ckeditor/init
  3. Create file lib/tasks/precompile_hook.rake and paste text from this answer Precompile hook
巴黎盛开的樱花 2025-01-05 02:43:02

您的代码中有语法错误。预编译属性是一个数组。

您可以将单个项目附加到数组中,如下所示:

config.assets.precompile << 'name_of_file.ext'

如果您的值位于数组中,则必须添加该数组。

config.assets.precompile += [ /.*config\.js/, /.*en.js/, /.*editor.css/ ]

如果追加,则会在预编译数组中嵌套一个数组,该数组将被忽略。

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:

config.assets.precompile << 'name_of_file.ext'

If your values are in an array then you have to ADD the array.

config.assets.precompile += [ /.*config\.js/, /.*en.js/, /.*editor.css/ ]

If you append then you'd have an array nested inside the precompile array, which is ignored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文