18

I'm using the ckeditor gem in my Rails 4 application. Everything works great locally and on my staging heroku environment, but I get this errors when pushing on the production environment :

GET http://myapp.herokuapp.com/assets/ckeditor/contents.css 404 (Not Found)
GET http://myapp.herokuapp.com/assets/ckeditor/skins/moono/icons.png 404 (Not Found)

The editor shows up well, but all icons are missing.

I followed the README (https://github.com/galetahub/ckeditor), but I'm probably missing something.

Here are my steps:

1) Gem installation, generate etc ...

2) config.autoload_paths += %W(#{config.root}/app/models/ckeditor) in application.js

3) mount Ckeditor::Engine => "/ckeditor" in routes.rb (I don't understand why)

4) In application.js

//= require ckeditor/override
//= require ckeditor/init

What is this doing exactly, why is override needed ? (Where are located these files, because there are not in /app/assets, neither in /lib/assets neither in /vendor/assets)

Heroku is read only oriented, therefore I can't run the rake task as explained in the tutorial. And I think this is why I get the errors in production mode.

Did anyone faced the same problem ? I ran through all stackoverflow questions, but nothing resolved my problem so far.

UPDATE :

The only way I found out to make it works is the live compilation : config.assets.compile = true But I would prefer not to use this in production, and I don't understand why it does work.

techdreams
  • 5,371
  • 7
  • 42
  • 63
Jérôme Boé
  • 2,752
  • 4
  • 21
  • 32
  • have you fixed this somehow? i have same problem, Rails 4 + Ckeditor gem + Ckeditor downloaded from their website, i have done everything in tutorial and i just get 404 (Not Found) in dev tools, is this a problem with routes? – Umren Jan 31 '14 at 21:52
  • I didn't have time to try it yet, this is why I didn't accept any answer. – Jérôme Boé Feb 01 '14 at 10:53
  • 1
    @Umren got your issue solved? I too have the same problem. – mgs Feb 13 '14 at 08:15
  • dunno if readme has been updated (or if you solved your issue) but they added a section to write a rake task that copies non-digested version of ckeditor assets in the proper place. Take a look at that, to me it's working ok, even without adding the path to the precompile.Same as proposed in the link suggested by @felix Ding – sissy Feb 13 '14 at 15:40
  • I have this issue too. – Brian Lau Dec 09 '16 at 02:26
  • I've the same problem. ckeditor works fine in development but not in production. I tested out everything suggested here and on github :-((( – Stef Hej May 01 '17 at 20:44

6 Answers6

15

Currently the solution for this problem has been changed.

There is no need to include "ckeditor/override.js"

1 Update your gem.

bundle update ckeditor

2 Add this line to your file config/application.rb

config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w( ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)

It works for me hope will work for you too.

Seb Wilgosz
  • 1,240
  • 15
  • 24
5

I just solved this problem following this: https://github.com/galetahub/ckeditor/issues/307#issuecomment-22186377 .

Basically, you add ckeditor asset to the precompile list in application.rb, use the rake task to copy them to the proper location during deployment.

Hope it helps.

Ding Yu
  • 141
  • 1
  • 11
  • actually there's a section also in the readme of the ckeditor gem with the same (working) solution, also to integrate the rake task in capistrano. – sissy Feb 13 '14 at 15:41
4

I followed the instructions on GitHub

You need to set with true the following variable in the file config/enviroments/production.rb

config.assets.compile = true

and add the following code

config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)

My environment to this solution was:

gem 'ckeditor', '~> 4.1'

ruby "2.3.0"

rails 5.0.0.1

Community
  • 1
  • 1
Henrique Jensen
  • 399
  • 3
  • 6
  • 3
    You dont want to have live compiling in production: [why not link](http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not) – Outside_Box Nov 25 '16 at 17:36
1

Adding config.assets.precompile += Ckeditor.assets in your application.rb should do the work.

0

I had the same problem, here are my files and how I fixed:

application.js

//= require ckeditor/override
//= require ckeditor/init

Gemfile

group :production do
  gem 'rails_12factor'
end

then run bundle to generate Gemfile.lock and commit files to your repo.

production.rb

config.serve_static_assets = true
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.assets.compile = false # we don't want compilation fallbacks

Deploy to heroku and verify it.

Hope that helps somehow.

bart
  • 186
  • 2
  • 4
0

I have been working on application and that works fine in dev env but when i am deploying it to Heroku assets are not loading at all & for that reason i am not able to load TinyMCE or CkEditor js or css.

I found out a work around and compiled assets locally and pushed to Heroku then i got the compiled assests url for CkEditor JS and included it in my view like

<script src="/assets/ckeditor/ckeditor.js"></script>

If you wanna load ckeditor assets from cloud u can use CDN like

<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.6.2/ckeditor.js"</script>

Also u need to change few settings in your production.rb file

  config.assets.compile = true
  config.assets.precompile += Ckeditor.assets
  config.assets.precompile += %w(ckeditor/* )
  config.autoload_paths += %W(#{config.root}/app/models/ckeditor)

and it starts working on Heroku as well.

For any other issues pls reply.

Amit
  • 174
  • 1
  • 7