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

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

问题描述

我能否以某种方式配置 Rails 以避免需要将 # coding: 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

它不会解决问题,但会为每个文件添加魔法行.相关主题:为什么升级到 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 应用程序中,您可以在应用程序配置中指定默认字符编码.

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

config/application.rb

看起来像:

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

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

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