我在 Rails 4 应用程序中使用 ckeditor gem。 在本地和我的stoku heroku环境中,一切都很好用,但是在推动生产环境时我遇到了这个错误:
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)
编辑器显示良好,但缺少所有图标。
我遵循自述文件(https://github.com/galetahub/ckeditor),但我可能错过了一些东西。
以下是我的步骤:
1)宝石安装,生成等...
2)config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
在application.js
3)mount Ckeditor::Engine => "/ckeditor"
(我不明白为什么)
4)在application.js
中//= require ckeditor/override
//= require ckeditor/init
这究竟是做什么的,为什么需要覆盖? (这些文件位于何处,因为/app/assets
中没有,/lib/assets
中的/vendor/assets
中都没有{/ 1>}
Heroku是面向只读的,因此我无法按照教程中的说明运行rake任务。 我认为这就是我在生产模式中得到错误的原因。
有没有人遇到同样的问题? 我查看了所有stackoverflow问题,但到目前为止还没有解决我的问题。
更新:
我发现让它发挥作用的唯一方法是实时编译:{{1}} 但我不想在生产中使用它,我不明白它为什么会起作用。
答案 0 :(得分:14)
目前,此问题的解决方案已更改。
无需包含“ckeditor / override.js”
1更新你的宝石。
bundle update ckeditor
2将此行添加到文件config / application.rb
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w( ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
它对我有用希望对你也有用。
答案 1 :(得分:5)
我刚刚解决了这个问题:https://github.com/galetahub/ckeditor/issues/307#issuecomment-22186377。
基本上,您将ckeditor资产添加到application.rb
中的预编译列表中,使用rake任务在部署期间将它们复制到正确的位置。
希望它有所帮助。
答案 2 :(得分:4)
我按照GitHub
上的说明操作您需要在文件 config / enviroments / production.rb
中设置true以下变量 config.assets.compile = true
并添加以下代码
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
我对此解决方案的环境是:
gem'ckeditor','〜> 4.1'
ruby“2.3.0”
rails 5.0.0.1
答案 3 :(得分:1)
在config.assets.precompile += Ckeditor.assets
中添加application.rb
可以完成工作。
答案 4 :(得分:0)
我有同样的问题,这是我的文件以及我如何修复:
//= require ckeditor/override
//= require ckeditor/init
group :production do
gem 'rails_12factor'
end
然后运行bundle以生成Gemfile.lock并将文件提交到您的repo。
config.serve_static_assets = true
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.assets.compile = false # we don't want compilation fallbacks
部署到heroku并验证它。
希望有所帮助。
答案 5 :(得分:0)
我一直致力于应用程序,并且在dev env中工作正常,但是当我将它部署到Heroku时,资源根本没有加载。因此我无法加载TinyMCE或CkEditor js或css。
我找到了一个解决方案并在本地编译资产并推送到Heroku然后我得到了CkEditor JS的编译的assests url并将其包含在我的视图中
<script src="/assets/ckeditor/ckeditor.js"></script>
如果您想从云中加载ckeditor资产,您可以使用CDN
<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.6.2/ckeditor.js"</script>
此外,您需要更改production.rb文件中的一些设置
config.assets.compile = true
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
它也开始在Heroku上工作。
对于任何其他问题,请回复。