Search code examples
ruby-on-railsckeditorruby-on-rails-5

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


I recently updated to Rails 5.2.2 (from 4.2.3) and now I'm getting this warning in the logs on pages using 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.

This is the line:

<%= javascript_include_tag :ckeditor %>

I tried adding skip_pipeline: true but then it started making requests for "/javascripts/ckeditor.js" which gave a 404 error.

Either way, the CKEditor works and the text field is rich text. I have this line in my application.js

 //= require ckeditor/init

It works even without the javascript_include_tag. I get the feeling the previous dev thought CKEditor was a large library and only wanted to include it on specific pages in the admin that needed it. How can that be achieved?


Solution

  • Rails is going to give you a JavaScript file per file in your JavaScript assets folder. For example, you should have a javascript_include_tag for :application because of that "application.js" file there. You’re including ckeditor into your application.js file, which is why ckeditor works. But, you’re trying to include a JavaScript file for an asset that doesn’t exist, meaning there is no "ckeditor.js" file in your javascripts folder.

    This message is coming from Rails attempting to look up the asset name for the js file, because in prod Rails tacks on a unique hash to the file name to prevent caching.

    This has likely been a problem the whole time, and you just never noticed the JavaScript file 404ing, and now Rails 5.2 is louder about the problem than 4.2 was.

    You should just delete the javascript_include_tag line.

    Alternatively you could create a ckeditor.js file, and move the //= require ckeditor/init from the application.js file over to ckeditor.js. Now you can do the javacript_include_tag only on pages that need it. But be wary of your load order. If you have any js in your application.js file that depends on ckeditor or vice versa, you’ll need to make sure you include your files in the right order in the html (the same order that the requires happened in, in application.js, assuming the order matters).