I can specify any ruby file to use specific encoding by add a comment line at its top:
#encoding: utf-8
But in Rails’ config/application.rb, I found this:
config.encoding = "utf-8"
Are they different? If I have set config.encoding = "utf-8", still I need #encoding: utf-8?
The
config.encoding = "utf-8"part inconfig/application.rbis related to how rails should interpret content.#encoding: utf-8in a ruby file tells ruby that this file contains non-ascii characters.These two cases are different. The first one (in
config/application.rb) tells rails something, and has nothing at all to do with how ruby itself should interpret source files.You can set the environment variable
RUBYOPT=-Kuif you’re lazy and want ruby to automatically set the default file encoding of.rbfiles toutf-8, but I’d rather recommend that you put your non-ascii bits in a translation file and reference that withI18n.t.