0

我正在开发 Rails 应用程序,一切正常,但现在它开始出现问题。我已经使用 Authlogic 易腐令牌实现了 ActionMailer,现在,每次我尝试访问 UsersController#show 时,它只显示错误 500。

We're sorry, but something went wrong.

并在服务器控制台中

Started GET "/users/1" for 127.0.0.1 at 2012-10-06 13:04:46 +0200
Processing by UsersController#show as HTML
  Parameters: {"id"=>"1"}
  User Load (2.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
   (1.0ms)  BEGIN
   (1.0ms)  UPDATE `users` SET `last_request_at` = '2012-10-06 11:04:46', `perishable_token` = 'eFBAhfqGX2p04ZfYGb9w', `updated_at` = '2012-10-06 11:04:46' WHERE `users`.`id` = 1
   (3.0ms)  COMMIT
  User Load (1.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Rendered users/show.html.erb within layouts/application (99.0ms)
Completed 500 Internal Server Error in 169ms

development.log 是空的。此外,当我重新启动服务器时,我的会话不会过期,所以我在重新启动后保持登录状态。一段时间后,我发现有时服务器会抛出此错误

[2012-10-06 13:11:39] ERROR Errno::ECONNABORTED: Software v hostitelsk�m poc�taci ukoncil vytvoren� pripojen�.
    C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `eof?'
    C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `run'
    C:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
C:/Ruby193/lib/ruby/1.9.1/webrick/htmlutils.rb:19: warning: regexp match /.../n against to CP850 string
C:/Ruby193/lib/ruby/1.9.1/webrick/htmlutils.rb:20: warning: regexp match /.../n against to CP850 string
C:/Ruby193/lib/ruby/1.9.1/webrick/htmlutils.rb:21: warning: regexp match /.../n against to CP850 string
C:/Ruby193/lib/ruby/1.9.1/webrick/htmlutils.rb:22: warning: regexp match /.../n against to CP850 string

我曾尝试使用 rails/console 一切正常。我没有选择,我被卡住了。我将不胜感激任何帮助。

4

1 回答 1

1

问题在于模型文件中的错误编码。我正在使用 UTF-8(用于 latin2 字符),我需要在我想使用变音符号的每个文件的开头添加它

#encoding: utf-8

不幸的是,我不知道任何更好的方法。如果我在没有设置编码的文件中使用变音符号,rails 将抛出关于无效多字节字符(US-ASCII)的错误。所以 UsersController#show 使用user.rb方法,该方法使用report.rb方法。method.rb文件中有变音符号,但我忘记添加编码行。不知何故,Ruby on Rails 无法处理该错误。并导致 500 内部错误

于 2013-01-19T18:14:12.950 回答