Encoding issues in javascript files using rails asset pipeline

后端 未结 1 742
醉酒成梦
醉酒成梦 2021-01-11 22:45

I\'m using rails 3.1 and the asset pipeline (ruby 1.9.2).

I get the following error when trying to serve a javascript js.erb file that has utf-8 encoded

相关标签:
1条回答
  • 2021-01-11 23:37

    When loading a file, Ruby tries to "guess" its encoding. If no UTF-8 or any other non-ASCII characters are found, it uses US-ASCII as encoding for the file and throws an error if it suddenly encounters a non-ASCII character, which e.g. is loaded at run-time.

    The best solution for this problem is to force Ruby to use a certain encoding by adding # encoding: utf-8 as the first line of a .rb file or <%# encoding: utf-8 %> if it's a .erb file.

    0 讨论(0)
提交回复
热议问题