在所有文件中添加“#coding:utf-8”

时间:2022-02-26 11:10:47

Can I somehow configure Rails to avoid the need to add # coding: utf-8 to all files? Or must I add it to each file manually?

我能以某种方式配置Rails以避免需要在所有文件中添加#coding:utf-8吗?或者我必须手动将其添加到每个文件?

UPD

UPD

To improve my life I have found this gem:

为了改善我的生活,我发现了这个宝石:

magic_encoding

magic_encoding

It won't fix the problem, but it will add magick line to each file. Related topic: Why are all strings ASCII-8BIT after I upgraded to Rails 3?

它不会解决问题,但它会为每个文件添加magick线。相关主题:为什么升级到Rails 3后所有字符串都是ASCII-8BIT?

1 个解决方案

#1


3  

In a rails application you can specify the default chracter encoding in your application config.

在rails应用程序中,您可以在应用程序配置中指定默认的chracter编码。

Add the following code inside the Application class in in config/application.rb

在config / application.rb中的Application类中添加以下代码

Looks something like:

看起来像:

# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"

#1


3  

In a rails application you can specify the default chracter encoding in your application config.

在rails应用程序中,您可以在应用程序配置中指定默认的chracter编码。

Add the following code inside the Application class in in config/application.rb

在config / application.rb中的Application类中添加以下代码

Looks something like:

看起来像:

# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"