Gem 安装 ckeditor 富文档,报错:couldn't find file 'ckeditor/init' with type 'application/javascript'

tankzhuchen · 2019年03月28日 · 最后由 yfscret 回复于 2019年04月09日 · 9225 次阅读

终端机详细报错

ActionView::Template::Error (couldn't find file 'ckeditor/init' with type 'application/javascript') Checked in these paths: /Users/zhuzhuchen/rails101/app/assets/config /Users/zhuzhuchen/rails101/app/assets/images /Users/zhuzhuchen/rails101/app/assets/javascripts /Users/zhuzhuchen/rails101/app/assets/stylesheets /Users/zhuzhuchen/rails101/vendor/assets/javascripts /Users/zhuzhuchen/rails101/vendor/assets/stylesheets /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/images /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/javascripts /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/stylesheets /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/jquery-rails-4.3.3/vendor/assets/javascripts /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/coffee-rails-4.2.2/lib/assets/javascripts /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actioncable-5.0.7.1/lib/assets/compiled /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/turbolinks-source-5.2.0/lib/assets/javascripts /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/stylesheets /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/javascripts /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/fonts `/Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/images): 4:

Rails101 5: <%= csrf_meta_tags %> 6: 7: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 8: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 9: 10:

app/assets/javascripts/application.js:17 app/views/layouts/application.html.erb:7:in_app_views_layouts_application_html_erb__4471122603424365335_70331191397360' Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.6ms) Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.5ms) Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms) Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (79.6ms)


我做了以下事情

安装gem 'ckeditor'

app/assets/javascripts/application.js加入一行//= require ckeditor/init

config/initializers/assets.rb加入一行Rails.application.config.assets.precompile += %w( application.css application.js ckeditor/* )

修改了 new 的 simple_formf.input :description, as: :ckeditor

https://github.com/galetahub/ckeditor

好像只需要这个 (未测试)

Rails.application.config.assets.precompile += %w[ckeditor/config.js]

你这个我刚才测试了一下,有两种解决方法(还有一种最简单的方法,gem 'ckeditor', '4.2.4' ): 1.你应该在 app/assets/javascripts 目录下新建个 ckeditor 目录,然后里头放上 config.js 文件,在 application.js 中加入 //= require ckeditor/init,这个文件在https://github.com/galetahub/ckeditor里有,

然后你这个

Rails.application.config.assets.precompile += %w[ckeditor/config.js]

放 ckeditor/*也行放 ckeditor/config.js 也行或者不放也行 2.上面那个是老版本时候的教程,现在我看https://github.com/galetahub/ckeditor把教程换了,在你操作的基础上需要

rails generate ckeditor:install

会生产 config/initializers/ckeditor.rb,然后你需要

Ckeditor.setup do |config|
  # //cdn.ckeditor.com/<version.number>/<distribution>/ckeditor.js
  config.cdn_url = "//cdn.ckeditor.com/4.6.1/basic/ckeditor.js"
end

然后在你的 new 或者 application.html.erb 页面加上

<% = javascript_include_tag Ckeditor.cdn_url %>

成功:

你按我的试试 有问题再问我

搞定了,感谢!2 楼的有用,我把 gem 换成 gem 'ckeditor', '4.2.4'

@yfscret 目前还出现了一个问题,部署上去以后没有显示编辑器,编辑器的位置是空白的

tankzhuchen 回复

这个可能是你 js 没加载上?这个我就不好说了,打开 f12 看看是不是 js 加载错误或者其他什么问题

需要 登录 后方可回复, 如果你还没有账号请 注册新账号