将UTF-8设置为Heroku中的默认字符串编码 [英] Set UTF-8 as default string encoding in Heroku

查看:116
本文介绍了将UTF-8设置为Heroku中的默认字符串编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将默认的ruby字符串编码更改为Heroku中的UTF-8。由于某种原因,它是US-ASCII。

I need to change the default ruby string encoding to UTF-8 in Heroku. For some reason it is US-ASCII.


$ heroku console
Ruby console for myapp.heroku.com 
>> "a".encoding 
=> #<Encoding:ASCII-8BIT>

但是,如果我运行irb本地我得到一个不同的结果:

However, if I run irb locally I get a different result:


$ irb 
ruby-1.9.2-p136 :001 > "a".encoding 
=> #<Encoding:UTF-8>

都运行在ruby 1.9.2上。我已经尝试设置这个,但是没有工作:

Both run on ruby 1.9.2. I've tried setting this as well, but didn't work:


Encoding.default_internal = Encoding.default_external = "UTF-8"

想法?

谢谢,
Felipe

Thanks, Felipe

推荐答案

根据Heroku支持人员,这是神奇的东西:

As per the Heroku support staff, this is the magic thing:


heroku config:add LANG=en_US.UTF-8

尽管 heroku控制台将继续报告字符串编码为 ASCII-8BIT ,您的实际应用将使用正确的编码运行,基于 LANG config var。
您可以通过这样做来加倍检查:

Although heroku console will keep reporting strings encoding as ASCII-8BIT, your actuall app will be running with the correct encoding, based on the LANG config var. You can double check that by doing this:


$ heroku run bash
Running bash attached to terminal... up, run.2
u20415@022e95bf-3ab6-4291-97b1-741f95e7fbda:/app$ irb
irb(main):001:0> "a".encoding
=> #<Encoding:UTF-8>

这篇关于将UTF-8设置为Heroku中的默认字符串编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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