error-handling - 404、500 的自定义错误页面,但默认的 500 错误消息来自哪里?

标签 error-handling ruby-on-rails-4

目前正在生产中,我收到以下文字:

500 Internal Server Error
If you are the administrator of this website, then please read this web application's
log file and/or the web server's log file to find out what went wrong.
该页面上没有任何 HTML。此代码位于何处?我没有 public/500.html 文件。
在我的 route ,我有:
  get "/404", :to => "errors#error_404"
  get "/422", :to => "errors#error_404"
  get "/500", :to => "errors#error_500"
  get "/505", :to => "errors#error_505"
错误 Controller :
class ErrorsController < ApplicationController

  def sub_layout
    "left"
  end

  def error_404
    render :status => 404, :formats => [:html], :layout => "white", :sub_layout => "left"
  end

  def error_422
    render :status => 422, :formats => [:html], :layout => "white", :sub_layout => "left"
  end

  def error_500
    render :status => 500, :formats => [:html], :layout => "white", :sub_layout => "left"
  end

  def error_505
    render :status => 505, :formats => [:html], :layout => "white", :sub_layout => "left"
  end

end
如何让它始终加载我的自定义错误?对于某些错误,它只会抛出来自 Ruby on Rails 核心某处的这两行文本。我希望它每次都能拾取我的自定义样式错误页面!

最佳答案

您遇到的错误是从
https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L18-L22
这意味着您的异常被拯救的代码本身就是抛出异常。
您可以检查日志中的文本:Error during failsafe response:确定异常的真正来源,从而解决您的问题。

关于error-handling - 404、500 的自定义错误页面,但默认的 500 错误消息来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19103759/

相关文章:

python - 如何确定证书验证错误

error-handling - 如果发生错误,请在jqgrid中的添加对话框中设置消息

ruby-on-rails-4 - 使用 capybara-webkit 的 Sidekiq 工作行为不稳定

html - HAML & 字体很棒;我最终在图标后看到了一个 5。我不想要按钮上的五个。

ruby-on-rails - 让 Puma Postgres Server 在开发中与 Heroku 合作,或者回到 Sqlite 有意义吗?

ruby - 如何在 Rails 4 中使用表单对象之前的验证回调?

ruby-on-rails - Rails 使用正则表达式验证不起作用?

c# - 在Dispose()中处理异常

android - AsyncTask、RejectedExecutionException 和任务限制

c++ - C++ 中的变量作用域?