In Ruby on Rails, are '#encoding: utf-8' and 'config.encoding = “utf-8”' different?

前端 未结 1 1643
失恋的感觉
失恋的感觉 2020-12-03 06:51

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/applica

相关标签:
1条回答
  • 2020-12-03 07:28

    The config.encoding = "utf-8" part in config/application.rb is related to how rails should interpret content.

    #encoding: utf-8 in 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=-Ku if you're lazy and want ruby to automatically set the default file encoding of .rb files to utf-8, but I'd rather recommend that you put your non-ascii bits in a translation file and reference that with I18n.t.

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