Encoding error in JavaScript resource in Rails

I have a Rails project (version 3.2.1) and I recently switched from Ruby 1.8.7 to Ruby 1.9.3. I have added code comments in all .rb and .erb , but I have a problem with the usual JavaScript .js attributes. They contain comments in Polish saved with the UTF-8 encoding. It works fine in most files - Ruby correctly defines the encoding, but in one file I have only one UTF-8 character ś in the comment line. And now the Rails server fails with Encoding::CompatibilityError when displaying the index page (which doesn't even reference the JavaScript file).

I know that this is a problem with detecting Ruby's automatic encoding, since it probably cannot detect a single-character encoding outside the ASCII range, but it is very frustrating, because in any case it does not matter - the file is associated only with the asset.

My question is: how to provide UTF-8 encoding in all .js assets?

+4
source share
1 answer

try renaming it to js.erb and placing <% # encoding: utf-8%> at the top

found a hint here: Encoding problems in javascript files using rails resource pipeline

+4
source

Source: https://habr.com/ru/post/1402886/


All Articles