4

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

I know it's a problem with Ruby's automatic encoding detection as it probably can't detect encoding from single character outside ASCII range, but it's very frustrating since it shouldn't matter anyway - the file is only linked to as an asset.

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

piotrdz
  • 43
  • 4

1 Answers1

4

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

found a hint here: Encoding issues in javascript files using rails asset pipeline

Community
  • 1
  • 1
Kodak
  • 1,779
  • 2
  • 18
  • 29