Heroku and Rails: how to set utf-8 as the default encoding

后端 未结 2 1840
暗喜
暗喜 2021-01-19 16:44

Today, I created a copy of a working app, which runs perfectly on Heroku, and tried to deploy it on Heroku as a starting point for a new project.

I added the new fol

相关标签:
2条回答
  • 2021-01-19 17:18

    I found this, much easier solution:

    Just add ENV['RUBYOPT'] = "-Ku" to your environment variables on Heroku. You can do this with figaro gem:

    1. Add gem "figaro" to your Gemfile
    2. bundle install
    3. Insert this code in config/application.yml:

      production:
        RUBYOPT: "-Ku"
      
    4. Run rake figaro:heroku

    Also, you can try with magic_encoding gem, but I dislike this approach.

    0 讨论(0)
  • 2021-01-19 17:23

    In your config/application.rb,

      config.encoding = "utf-8"
    

    in the database.yml,

     development:
         adapter:  mysql2(whatever your db)
         host:     localhost
         encoding: utf8
    

    you also have to add(including the hash)

    # encoding: UTF-8
    

    source:http://craiccomputing.blogspot.com/2011/02/rails-utf-8-and-heroku.html

    0 讨论(0)
提交回复
热议问题