New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a ckeditor version working with Rails 4 production? #307

Closed
bsylvain opened this Issue Aug 4, 2013 · 42 comments

Comments

Projects
None yet
@bsylvain
Copy link

bsylvain commented Aug 4, 2013

I tried th classic gem "ckeditor" version and this one :

gem "ckeditor", :git => "https://github.com/adamico/ckeditor.git",
:branch => "rails-4-compatibility"

I can go around the bug of textarea not recognized with adamico version. Howerver when pushed in production it does not work, ckeditor want to load the assets without the digest :

(No route matches [GET] "/assets/ckeditor/config.js")

I use thoses settings in application.rb :

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

How can i make ckeditor works in rails 4? Is it possible?

@danielboggs

This comment has been minimized.

Copy link

danielboggs commented Aug 4, 2013

I am having the same struggle right now. I have heard of people copying assets manually to /public/assets/ckeditor but I'm not sure what exactly needs to be copied. Perhaps someone will chime in here.

@danielboggs

This comment has been minimized.

Copy link

danielboggs commented Aug 6, 2013

I arrived a solution for this that requires creating a rake task that couples with "assets:precompile" to create "non-digested" versions of the ckeditor asset files after pushing to production. I made a /lib/tasks/ckeditor.rake file with the following task...

require 'fileutils'

desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" do
  fingerprint = /\-[0-9a-f]{32}\./
  for file in Dir["public/assets/ckeditor/**/*"]
    next unless file =~ fingerprint
    nondigest = file.sub fingerprint, '.'
    FileUtils.cp file, nondigest, verbose: true
  end
end

Also I had to add an extra line to my application.rb file from what you have above so that assets:precompile included all the image assets needed by ckeditor.

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

This comment has been minimized.

Copy link

bsylvain commented Aug 10, 2013

It works great! Thank you.

@sergeymild

This comment has been minimized.

Copy link

sergeymild commented Aug 10, 2013

Thanks i wait it very long, works works works!!!!

@markbao

This comment has been minimized.

Copy link

markbao commented Sep 4, 2013

The above fix runs into an issue when you have multiple copies of CKEditor assets in public/assets/ckeditor. I ran into this issue when I compiled config.js and then changed it, and compiled again.

I ended up with two config.js files in public/assets/ckeditor:

config-aa96b1f1541395ea16fca922151f0ac0.js   # new
config-f41952e10a5728835a88f232e72bdcae.js   # old

However, the rake task above blindly copies a file with any fingerprint to the nondigested version of the file (as in config-[any_fingerprint].js to config.js):

# original code
  for file in Dir["public/assets/ckeditor/**/*"]
    next unless file =~ fingerprint
    nondigest = file.sub fingerprint, '.'
    FileUtils.cp file, nondigest, verbose: true
  end

So this happens:

config-aa96b1f1541395ea16fca922151f0ac0.js [new] -----copy------> config.js [now new]
config-f41952e10a5728835a88f232e72bdcae.js [old] ---overwrite---> config.js [now old]

The new config.js is overwritten by the old one. The way to solve this is to check the latest digest of each file, and to make sure the file being copied matches the latest digest.

Here is the version of lib/tasks/ckeditor.rake modified by me to work: https://gist.github.com/markbao/6431880

Reproduced below. The puts are there so you know what's going on; feel free to remove them.

require 'fileutils'

desc "Create nondigest versions of all ckeditor digest assets"
task "assets:precompile" => :environment do
  fingerprint = /\-([0-9a-f]{32})\./
  for file in Dir["public/assets/ckeditor/**/*"]
    # Skip file unless it has a fingerprint
    next unless file =~ fingerprint

    # Get filename of this file without the digest
    # (example) public/assets/ckeditor/config.js
    nondigest = file.sub fingerprint, '.'

    # Create a filename relative to public/assets
    # (example) public/assets/ckeditor/config.js => ckeditor/config.js
    filename = nondigest.sub 'public/assets/', ''
    filename = filename.sub /.gz$/, ''          # Remove .gz for correct asset checking

    # Fetch the latest digest for this file from assets
    latest_digest = Rails.application.assets.find_asset(filename).digest

    # Debug information
    puts '---- ' + file + ' ----'

    # Compare digest of this file to latest digest
    # [1] is the enclosed capture in the fingerprint regex above
    this_digest = file.match(fingerprint)[1]
    if (this_digest == latest_digest)
      # This file's digest matches latest digest, copy
      puts 'Matching digest, copying ' + file
      FileUtils.cp file, nondigest, verbose: true
    else
      # This file's digest doesn't match latest digest, ignore
      puts 'Latest digest: ' + latest_digest
      puts 'This digest:   ' + this_digest
      puts 'Non-matching digest, not copying ' + file
    end

    # Debug information
    puts '---- end ----'
  end
end
@avitus

This comment has been minimized.

Copy link

avitus commented Sep 5, 2013

I had to change this line above:

latest_digest = Rails.application.assets.find_asset(filename).digest

to

latest_digest = Rails.application.assets.find_asset(filename).try(:digest)

in order to handle some missing image files.

@mrfoto

This comment has been minimized.

Copy link

mrfoto commented Sep 30, 2013

This was the only way to get it running on Heroku for me. I don't know but it seems kinda hackish. Isn't there a more assetish way to do it?

Also @galetahub why does it say that the gem has "Rails 4 integration", when there are this kind of hacks required to get it running in production?

@danielboggs

This comment has been minimized.

Copy link

danielboggs commented Sep 30, 2013

FYI the latest app I deployed (last week) doesn't need the rake task at all to work in production now. Using the ckeditor gem version 4.0.6

@mrfoto

This comment has been minimized.

Copy link

mrfoto commented Sep 30, 2013

Oh, cool. Well it didn't work for me before but it works now somehow 😆 No idea what was/is going on. Thanks!

@alexpls

This comment has been minimized.

Copy link

alexpls commented Oct 4, 2013

I'm running the 4.0.6 gem and I still had to use the custom Rake task above to get CKEditor to work in production.

@danielboggs

This comment has been minimized.

Copy link

danielboggs commented Oct 4, 2013

My mistake on my last comment. I just realized I still had the rake task in from an older version of the app >.<

@Preen

This comment has been minimized.

Copy link

Preen commented Oct 11, 2013

This still is an issue

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Oct 11, 2013

I used this rake task in my rails 4 app and it mostly fixed the issue. The only thing that is NOT rendering now are the icons for the toolbar buttons. I'm still getting a 404 for 'icons.png'.

screen shot 2013-10-11 at 3 51 52 pm

I used the code as it is (without debug code).

Any idea as to why they aren't showing?

@danielboggs

This comment has been minimized.

Copy link

danielboggs commented Oct 11, 2013

i had to add the following to application.rb to get the icons to work.

config.assets.enabled = true
config.assets.precompile += Ckeditor.assets
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
@zlx

This comment has been minimized.

Copy link
Contributor

zlx commented Oct 12, 2013

@miriamdeana I resolved the problem with cp /home/deploy/rails_apps/smart_lion/shared/bundle/ruby/2.0.0/gems/ckeditor-4.0.6/vendor/assets/javascripts/ckeditor/skins/moono/icons.png public/assets/ckeditor/skins/moono/

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Oct 12, 2013

@danielboggs Thanks for responding! Yeah, I already had that in the config/application file.

@zix I will definitely try that. Since I last commented, I went tot he add-ons page for moono and dowloaded the skin to the public/assets/ckeditor/skins/ folder to no avail. It looks like this is similar but will try this specifically and report back. Thx!

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Oct 16, 2013

Ok. @zix, I tried that, and still nothing changed. Just to be certain, I found the path for icons.png, copied it to the path you provided.

Btw, the icons show up fine in development, but on the beta site they don't.

@zlx

This comment has been minimized.

Copy link
Contributor

zlx commented Oct 16, 2013

@miriamdeana Do you get the same error? the icon.png is not 404. Maybe you can check the public dir for image and confirm it can visited by url

@CodeOfficer

This comment has been minimized.

Copy link
Contributor

CodeOfficer commented Oct 30, 2013

I have a pull request which may help with this, I added another line to the documentation on compatibility with rails 4 in the README. Specifically to copy folders of assets nested under your ckeditor folder in the rake task.

#341

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Oct 31, 2013

@zix Here are the headers for icon.png (Click to expand):

screen shot 2013-10-31 at 1 21 36 pm

It stills says 404.

@CodeOfficer How should I use this pull request?

@CodeOfficer

This comment has been minimized.

Copy link
Contributor

CodeOfficer commented Oct 31, 2013

@miriamdeana It's just a one line modification to the suggested rake task in the README ... I observed that it was trying to copy assets but not taking into account subfolders like 'images'.

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Oct 31, 2013

ok. Thanks @CodeOfficer I wasn't using that rake task at all, so I have now included it in lib/tasks/ckeditor.rake and commented out the one that was suggested by @markbao above ( https://gist.github.com/markbao/6431880 ).

I have deployed and i still cannot see any icons.

@CodeOfficer

This comment has been minimized.

Copy link
Contributor

CodeOfficer commented Oct 31, 2013

@miriamdeana This is the rake task I was referring to, Scroll down to "Usage with Rails 4 assets".

https://github.com/galetahub/ckeditor

This README commit was added 8 days ago here: f2506d4

My PR just adds one line to that.

@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Nov 1, 2013

@CodeOfficer I think you misunderstood me; that's exactly what I did.

I added THAT rake task to my file and removed the one that I had previously included. So, it did not change the outcome for me.

@CodeOfficer

This comment has been minimized.

Copy link
Contributor

CodeOfficer commented Nov 3, 2013

@miriamdeana Ah right then, not sure if this is an option for you, but I also needed this config option in production as well.

# Fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
@miriamdeana

This comment has been minimized.

Copy link

miriamdeana commented Nov 4, 2013

YES!!!! That worked! Thank you so very much @CodeOfficer . Obviously, this was not an urgent issue, but it was bugging me all the same.

I changed that setting to true in beta.rb and production.rb, and all is well.

@CodeOfficer

This comment has been minimized.

Copy link
Contributor

CodeOfficer commented Nov 4, 2013

Yay, glad to help. I don't like that I had to resort to that. I'd love to see the manifest issue fixed.

@jonahbron

This comment has been minimized.

Copy link

jonahbron commented Nov 16, 2013

I too got it to work by enabling config.assets.precompile. Of course it's not an optimal solution, but it will do for now. The rake tasks proposed don't work because I'm deploying to Heroku, which has a read-only filesystem :-( .

The issue I'm running into, though, is my config.js file is now outdated. I tried adding it to the precompile array, but it is still not showing the changes I've made to it in production. Any proposed solutions? How can I clear out the assets on Heroku so that the freshly compiled version is served?

@jonahbron

This comment has been minimized.

Copy link

jonahbron commented Nov 19, 2013

I was able to get it to clear the config.js cache by incrementing the assets version. Again not optimal, but it worked.

@rudedoc

This comment has been minimized.

Copy link

rudedoc commented Dec 15, 2013

Thanks everyone for the pointers above, I was deploying Monologue to Heroku, I set my:

config.assets.compile = true

in config/production.rb file.

This got me up and running.

akfreas added a commit to akfreas/sashimisite that referenced this issue Dec 16, 2013

@richpeck

This comment has been minimized.

Copy link

richpeck commented Feb 9, 2014

If your icons aren't loading on Heroku, add this to your application.rb:

    config.assets.precompile += ['*ckeditor/skins/moono/icons.png']
@macool

This comment has been minimized.

Copy link

macool commented Mar 3, 2014

My icons aren't loading either

@benjaminwood

This comment has been minimized.

Copy link

benjaminwood commented Mar 3, 2014

+1. I'm on heroku and I had the same issues.

It's not ideal but config.assets.compile = true in production.rb works for me. It's only admins that are affected by this, so I don't really care that it's slower than it could/should be. The rake task is cool, but I don't want to have to worry about running it and committing those files. 😄

@abreckner

This comment has been minimized.

Copy link

abreckner commented May 12, 2014

Instead of setting assets.compile to true, have you tried this?

Rails.application.config.assets.precompile += %w(
  ...
  Ckeditor.assets
  ckeditor/*
  monologue/*
  ...
)

ofagbemi added a commit to ofagbemi/gist that referenced this issue May 14, 2014

scmx added a commit to standout/standoutcms that referenced this issue May 15, 2014

Fix CKEditor assets which didn't load
This gem makes it so that all assets are available without digest hash
I chose this instead of a rake task:
galetahub/ckeditor#307 (comment)
@introvert

This comment has been minimized.

Copy link

introvert commented Jun 4, 2014

Why the heck would someone want to precompile ckeditor assets everytime other assets are precompiled? I would just put the ckeditor files in /public/ckeditor folder and avoid long and unnecessary precompilation time with precompiling them manually when required.

@vjnunez

This comment has been minimized.

Copy link

vjnunez commented Jun 9, 2014

Hey @introvert, how can i skip asset precompilation ONLY for ckeditor assets? As you say, its nosense to precompile these assets everytime, the waiting time is killing me.

@benjaminwood

This comment has been minimized.

Copy link

benjaminwood commented Jun 25, 2014

@vjnunez and anybody that may want to effectively disable ckeditor asset precompilation:

You can prevent most of ckeditor assets from precompiling by adding this to your ckeditor config initializer: config.assets_plugins = []

This doesn't get rid of all ckeditor assets, though. Here's how to prevent a few more from loading:

Ckeditor assets are added to rails asset pipeline here:
https://github.com/galetahub/ckeditor/blob/master/lib/ckeditor/engine.rb#L8

There is currently no option to disable this completely. I think the correct solution would be adding a configuration option that can be controlled in the ckeditor initializer file. I don't have time to do this myself at the moment, so I've implemented this dirty hack in my applicaiton.rb:

config.after_initialize do
  Rails.application.config.assets.precompile = Rails.application.config.assets.precompile - Ckeditor.assets
end

Basically after_initialize (http://apidock.com/rails/Rails/Railtie/Configuration/after_initialize) is executed after your application has fully loaded (ckeditor has added its assets). The above modifies the precompile assets array by removing the ckeditor assets that were just added via the ckeditor gem.

Even after this you'll still have a few ckeditor assets precompiling (mostly related to the gems filebrowser plugin). I'm not sure how to prevent the remainder from loading, but this gets things pretty close and precompilation time is MUCH faster now (I've checked the assets into my public/assets directory and will update them manually when needed).

lukaselmer added a commit to renuo/ckeditor that referenced this issue Jul 4, 2014

lukaselmer added a commit to renuo/ckeditor that referenced this issue Jul 4, 2014

JayantGandhi pushed a commit to JayantGandhi/bcjournal that referenced this issue Nov 10, 2014

@mohnstrudel

This comment has been minimized.

Copy link

mohnstrudel commented Feb 5, 2017

Wow, it's 2017 and I've got still same issues with making CKEditor work in Production (VDS).

@peter-hank

This comment has been minimized.

Copy link

peter-hank commented Apr 6, 2017

If you need a handy solution, install https://rubygems.org/gems/non-stupid-digest-assets (haha).

And then create config/initializers/non_digest_assets.rb with the following content:

NonStupidDigestAssets.whitelist += [/ckeditor\/.*/]

Recompile the assets and it should work. There's no need to set config.assets.compile = true.

cristofer added a commit to cristofer/rails-blog that referenced this issue Jul 13, 2017

@sammyjopeters

This comment has been minimized.

Copy link

sammyjopeters commented Jul 23, 2017

4 years later, @danielboggs' suggestion (with @markbao's additions) got this working for me.

Sorry @peter-hank - I couldnt get non-stupid-digest-assets to work.

@Landoooooo

This comment has been minimized.

Copy link

Landoooooo commented Nov 14, 2017

I've followed @danielboggs and @markbao suggestions and Im still unable to get it to work with heroku.

@stale

This comment has been minimized.

Copy link

stale bot commented Dec 4, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 4, 2018

@stale stale bot closed this Dec 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment