Problems with ckeditor running on production Rails application with Heroku

半世苍凉 提交于 2019-11-29 00:24:42

问题


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.


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/19777316/problems-with-ckeditor-running-on-production-rails-application-with-heroku

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