經過數小時的谷歌搜索和挖掘,我發現解決方案,(我希望)可能有助於有相似或相同問題的人。
我做bundle exec rake --trace db:migrate
臨時服務器上,並得到了以下錯誤消息:
rake aborted!
"\xC5" on US-ASCII
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `read'
/var/www/myapp/test.myapp.com/releases/20111230233802/config/application.rb:5:in `<top (required)>'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `require'
/var/www/myapp/test.myapp.com/releases/20111230233802/Rakefile:4:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/var/www/myapp/test.myapp.com/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
所以我跳下來的config/application.rb
文件,以找出可能上升的誤差。該文件的第5行加載外部配置文件:
require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))
和外部文件包含UTF-8字符,而不是US-ASCII。所以我嘗試了幾種不同的解決方案來解決這個問題。
這工作對我來說,只有一個是對config/application.rb
文件的頂部添加一個額外的代碼幾行:
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
只是告訴耙使用UTF-8編碼來加載外部文件。在那之後,一切都變得順利,完全如預期。問題解決了!
PS。
我真的不知道爲什麼rake 0.9的開發者改變了之前Rake 0.8的行爲,這對我來說很好,對你來說也可能很好。也許你有一個想法,爲什麼?我很好奇。
您在部署的服務器上使用Ruby 1.9.x,在開發服務器上使用1.8.x? – smathy 2011-12-31 01:51:21
你可能想嘗試耙0.9.2.2而不是0.9.2.2 – house9 2011-12-31 07:16:26
另外,是capistrano運行rake db:使用bundle exec遷移? – house9 2011-12-31 07:17:42