添加“#coding:utf-8”到所有文件 [英] Add "# coding: utf-8" to all files

查看:100
本文介绍了添加“#coding:utf-8”到所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

UPD

我的生活我发现这个宝石:

To improve my life I have found this gem:


magic_encoding

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

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?

推荐答案

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

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

应用程序类中的以下代码添加到 config / application.rb

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

看起来像:

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

这篇关于添加“#coding:utf-8”到所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆