Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 828
IdahoEv Avatar asked Jan 26 '12 18:01

IdahoEv


2 Answers

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

like image 121
rdamborsky Avatar answered Sep 22 '22 22:09

rdamborsky


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
like image 36
Zh Kostev Avatar answered Sep 20 '22 22:09

Zh Kostev