Set UTF-8 as default string encoding in Heroku

前端 未结 1 1926
滥情空心
滥情空心 2020-12-01 15:00

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\"         


        
相关标签:
1条回答
  • 2020-12-01 15:12

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

    heroku config:add LANG=en_US.UTF-8
    

    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>
    
    0 讨论(0)
提交回复
热议问题