运行Web服务并尝试停止MySql Rails时,首先抛出:
ActiveRecord::StatementInvalid (Mysql::Error: MySQL server has gone away:...
哪个是可以接受的。但是在关闭过程完成后,它只会从公共文件夹中抛出500页并记录下来:
Rendered rescues/_trace (39.0ms)
Rendered rescues/_request_and_response (1.0ms)
Rendering rescues/layout (internal_server_error)
/!\ FAILSAFE /!\ Fri Dec 30 16:59:58 +0200 2011
Status: 500 Internal Server Error
Can't connect to MySQL server on 'localhost' (10061)
c:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/mysql_adapter.rb:620:in `real_connect'
c:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/mysql_adapter.rb:620:in `connect'
c:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/mysql_adapter.rb:203:in `initialize'
问题:是否有可能处理或解救这500错误,所以我可以这样:
rescue_from SomeGlobalError do |ex|
respond_to do |format|
format.html { ... }
format.all { ... }
end
end
这已在here中突出显示,但答案是错误的。你无法从控制器中拯救这个东西,那个问题让人感到难过的是“它没有事件到达控制器......它在某处失败了:active_record”
所以我仍在寻找解决方案。有帮助吗?
答案 0 :(得分:-1)
将此添加到您的config/database.yml
:
reconnect: true
您需要将它添加到每个环境中!你无法拯救ActiveRecord::StatementInvalid
,因为它不仅因为无效的陈述而失去联系或超时,......