Question

I am trying to use ckeditor (4.0.6) with Using rails_admin (0.5.0) in Rails 4.0 on DigitalOcean server.

I have included it in the rails_admin.rb initializer as follows and it works in production mode on my local

  config.model Faq do
    field :display_order
    field :question
    field :answer, :ck_editor  
  end

However on DigitalOcean when I go into Rails_Admin and try to make a new FAQ object it won't load ckeditor because it can't find the js.

 http://dummy.com/assets/ckeditor/ckeditor.js?_=1381313244552 404 (Not Found)
rails_admin-5daa9b7b76a226bdfa46a07fdaf2d77d.js:3

How can I fix this?

Was it helpful?

Solution

The problem is because Rails assets compile actually added a fingerprint on to the assets file of every CKeditor file, while the rails-admin is looking for a non fingerprint version of the file.

This issue only happens in the rails 4 with ckeditor. Actually the Readme.md of the ckeditor gem did mention about the issue and how to resolve it, but it isn't complete.

To resolve you could write a rake file to remove all the fingerprints and run this during deployment.

Here is my solution to resolve this issue.

Create a rake file in lib/tasks/ckeditor.rake with the following code

namespace :ckeditor do
  desc 'Create nondigest versions of some ckeditor assets (e.g. moono skin png)'
  task :create_nondigest_assets do
    fingerprint = /\-[0-9a-f]{32}\./
    for file in Dir[File.join('public/assets/ckeditor', '**', '*.js'),
                    File.join('public/assets/ckeditor', '**', '*.js.gz'),
                    File.join('public/assets/ckeditor', '**', '*.css'),
                    File.join('public/assets/ckeditor', '**', '*.png'),
                    File.join('public/assets/ckeditor', '**', '*.gif')]
      next unless file =~ fingerprint
      nondigest = file.sub fingerprint, '.' # contents-0d8ffa186a00f5063461bc0ba0d96087.css => contents.css
      FileUtils.cp file, nondigest, verbose: true
    end
  end
end

For Capistrano user, make sure you include this in your deploy.rb

desc 'copy ckeditor nondigest assets'
task :copy_nondigest_assets, roles: :app do
  run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} ckeditor:create_nondigest_assets"
end
after 'deploy:assets:precompile', 'copy_nondigest_assets'

For Heroku user, you would need to run the rake file manually each time before you check in your code. Make sure you do your rake assets:precompile before this.

rake ckeditor:create_nondigest_assets

Hope it helps

OTHER TIPS

I don't know, have you precompiled your assets?

If you're switching from a different kind of host, like Heroku, you may forget that you have to manually precompile your assets. You're lucky, though – it's easy!

RAILS_ENV=production rake assets:precompile If you run into problems, try running this instead:

RAILS_ENV=production rake assets:precompile:primary

From https://www.digitalocean.com/community/articles/how-to-launch-your-ruby-on-rails-app-with-the-digitalocean-one-click-image

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top