弃用警告:资产 "ckeditor.js" 不存在于资产 pipeline.Falling 中,回到可能位于 public 文件夹中的资产

DEPRECATION WARNING: The asset "ckeditor.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder

我最近更新到 Rails 5.2.2(从 4.2.3),现在我在使用 CKEditor gem 的页面日志中收到此警告。

DEPRECATION WARNING: The asset "ckeditor.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder. This behavior is deprecated and will be removed. To bypass the asset pipeline and preserve this behavior, use the skip_pipeline: true option.

这是行:

<%= javascript_include_tag :ckeditor %>

我尝试添加 skip_pipeline: true,但随后它开始请求“/javascripts/ckeditor.js”,出现 404 错误。

无论哪种方式,CKEditor 都能正常工作,并且文本字段是富文本格式。我的 application.js

中有这一行
 //= require ckeditor/init

即使没有 javascript_include_tag 也能正常工作。我感觉以前的开发人员认为 CKEditor 是一个大型库,只想将它包含在需要它的管理员的特定页面上。如何实现?

这有效

<%= javascript_include_tag 'ckeditor/init' %>

我还注释掉了应用程序清单中的行

// only load on required pages // require ckeditor/init

Rails 将为您的 JavaScript 资产文件夹中的每个文件提供一个 JavaScript 文件。例如,您应该为 :application 设置一个 javascript_include_tag,因为那里有 "application.js" 文件。您将 ckeditor 包含到 application.js 文件中,这就是 ckeditor 起作用的原因。但是,您正在尝试为不存在的资产包含一个 JavaScript 文件,这意味着您的 javascripts 文件夹中没有 "ckeditor.js" 文件。

此消息来自 Rails 试图查找 js 文件的资产名称,因为在产品中 Rails 对文件名附加了唯一的哈希值以防止缓存。

这可能一直是个问题,您只是从未注意到 JavaScript 文件 404ing,现在 Rails 5.2 比 4.2 更清楚这个问题。

您应该只删除 javascript_include_tag 行。

或者您可以创建一个 ckeditor.js 文件,然后将 //= require ckeditor/init 从 application.js 文件移动到 ckeditor.js。现在您可以只在需要它的页面上执行 javacript_include_tag。但要注意你的加载顺序。如果您的 application.js 文件中有任何依赖于 ckeditor 的 js,反之亦然,您需要确保以正确的顺序将文件包含在 html 中(与要求的顺序相同发生在 application.js,假设顺序很重要)。