这绝对是我们的代码和数据库的语言问题 包含中文字符。
****这是我的环境:
关于您的应用程序的环境 Ruby版本1.9.1(i386-mingw32) RubyGems版本1.3.5 机架版1.0 Rails版本2.3.5 Active Record版本2.3.5 Active Resource版本2.3.5 Action Mailer版本2.3.5 Active Support版本2.3.5 应用程序根C:/ path_to_my_root 环境发展 数据库适配器mysql 数据库架构版本20100327010640
****这是我的localhost; 3000运行我的ruby服务器之后:
ArgumentError in HomeController#construction
invalid byte sequence in GBK
RAILS_ROOT: C:/path_to_my_root
Application Trace | Framework Trace | Full Trace
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template_error.rb:43:in `split'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template_error.rb:43:in `source_extract'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template_error.rb:86:in `compute_backtrace'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template_error.rb:11:in `initialize'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template.rb:212:in `new'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template.rb:212:in `rescue in render_template'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
template.rb:205:in `render_template'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
base.rb:265:in `render'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
base.rb:352:in `_render_with_layout'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_view/
base.rb:262:in `render'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/base.rb:1250:in `render_for_file'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/base.rb:951:in `render'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/benchmarking.rb:51:in `block in
render_with_benchmark'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/
active_support/core_ext/benchmark.rb:17:in `block in ms'
C:/Ruby19/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/
active_support/core_ext/benchmark.rb:17:in `ms'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/benchmarking.rb:51:in `render_with_benchmark'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:135:in `block in custom'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:179:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:179:in `block in respond'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:173:in `each'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:173:in `respond'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/mime_responds.rb:107:in `respond_to'
C:/Users/Howard/Documents/local/vjoin/app/controllers/
home_controller.rb:53:in `construction'
.....
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/
methodoverride.rb:24:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/params_parser.rb:15:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/session/cookie_store.rb:93:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/failsafe.rb:26:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lock.rb:11:in
`block in call'
:8:in `synchronize'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/lock.rb:11:in
`call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/dispatcher.rb:114:in `block in call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/reloader.rb:34:in `run'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/
action_controller/dispatcher.rb:108:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails/rack/
static.rb:31:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in
`block in call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in
`each'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in
`call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails/rack/
log_tailer.rb:17:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/
content_length.rb:13:in `call'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/rack-1.0.1/lib/rack/handler/
webrick.rb:50:in `service'
C:/Ruby19/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
C:/Ruby19/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
C:/Ruby19/lib/ruby/1.9.1/webrick/server.rb:183:in `block in
start_thread'
Request
Parameters:
None
Show session dump
Response
Headers:
{"Cache-Control"=>"no-cache",
"Content-Type"=>"text/html"}
****我该怎么办?我试着在网上搜索,没找到多少。 我发现的唯一一件事就是把以下内容放进去 application_controller:
before_filter :set_charset, :set_locale
def set_charset
response.headers["Content-Type"] = "text/html; charset=utf-8"
WIN32OLE.codepage = WIN32OLE::CP_UTF8 end
但这仍然不起作用。 我是铁杆上的新手,所以不太了解它。
感谢您的帮助。
答案 0 :(得分:6)
Linux的:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
视窗:
set LC_ALL=en_US.UTF-8
set LANG=en_US.UTF-8
答案 1 :(得分:1)
尝试将ruby降级到1.8.7并查看这是否对您有所帮助。 (最简单的测试方法就是使用RVM(http://rvm.beginrescueend.com/)
在我的案例中,我能够通过确保包括以下内容来解决问题:
编码:utf8
在我的databases.yml
中