Heroku和Rails:如何将utf-8设置为默认编码 [英] Heroku and Rails: how to set utf-8 as the default encoding
问题描述
现在应用程序在启动时崩溃了,因为Heroku在我的源文件中发现了一些utf-8文本,并且无法识别它们:
2011-06-27T14:23:10 + 00:00 app [web.1]:/app/app/controllers/home_controller.rb:118:无效多字节字符(US-ASCII)
2011-06-27T14:23:10 + 00:00 app [web.1]:/app/app/controllers/home_controller.rb:118:语法错误,意外$ end,期待'}'
2011 -06-27T14:23:10 + 00:00 app [web.1]:... tue azioni,conquista lacittà!}
如何告诉Rails和Heroku我的所有源文件都是utf-8编码的?
我应该做广告d每个文件中的UTF-8 BOM?这真是太疯狂了,我以前的应用程序运行得非常漂亮。
我使用的是Rails 2.3.6。
在你的config / application.rb中,
database.yml中的 config.encoding =utf-8
,
开发:
适配器:mysql2(无论您的数据库)
主机:localhost
编码:utf8
您还必须添加(包括散列)
#encoding:UTF-8
来源: http://craiccomputing.blogspot.com/ 2011/02 / rails-utf-8-and-heroku.html
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 folder as a git repository, created a new remote repository on GitHub, edited the config file and gave new names to the databases, created the new databases and tried to deploy on Heroku.
Now the app crashed on startup because Heroku finds some utf-8 text inside my source files and doesn't recognize them:
2011-06-27T14:23:10+00:00 app[web.1]: /app/app/controllers/home_controller.rb:118: invalid multibyte char (US-ASCII)
2011-06-27T14:23:10+00:00 app[web.1]: /app/app/controllers/home_controller.rb:118: syntax error, unexpected $end, expecting '}'
2011-06-27T14:23:10+00:00 app[web.1]: ...tue azioni, conquista la città!"}
How can I tell Rails and Heroku that all of my source file are utf-8 encoded? Should I add a UTF-8 BOM in EVERY file? That's crazy and I was not doing so in my previous app that worked beautifully.
I'm using Rails 2.3.6.
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
这篇关于Heroku和Rails:如何将utf-8设置为默认编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!