How to get ckeditor resources to compile and load in Rails 3.1 asset pipeline

孤街浪徒 提交于 2019-12-30 21:27:00

问题


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?


回答1:


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




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/9023523/how-to-get-ckeditor-resources-to-compile-and-load-in-rails-3-1-asset-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!