我已经安装了 Rails exception_handler并尝试按照说明设置自定义错误处理,但是我仍然收到 gem 创建的标准 500 错误消息:
500内部服务器错误
如果您是本网站的管理员,请阅读此 Web 应用程序的日志文件和/或 Web 服务器的日志文件以找出问题所在。
这是我添加的内容config/application.rb
:
class Application < Rails::Application
config.exception_handler = {
dev: true,
layouts: {
'500' => 'exception'
}
}
end
我在以下位置创建了一个异常布局layouts/exception.html.erb
:
<!DOCTYPE html>
<html>
<head>
<title><%= "Error - #{@exception.status} Error" %></title>
</head>
<body>
<div class="container">
<%= yield %>
</div>
</body>
</html>
并使用以下命令生成默认异常视图:rails generate exception_handler:views
<div class="error">
<% if /^(5[0-9]{2})$/ =~ @exception.status.to_s %>
<!--Message -->
<%= content_tag :div, class: "message" do %>
<%= content_tag :div, class: "title" do %>
<span><%= "#{@exception.status} Error - #{details[:name]}" %></span>
<%= link_to image_tag("exception_handler/close.png"), main_app.root_url, title: "Close (Go back home)", class: "close" %>
<% end %>
<%= content_tag :div, class: "details" do %>
<%= image_tag "exception_handler/alert.png", title: "#{@exception.status} Error" %>
<div class="status"><%= @exception.status %> Error</div>
<% end %>
<%= content_tag :div, class: "info" do %>
<span><%= details[:description] %></span>
<div class="notification">
<%= link_to image_tag("exception_handler/home.png", title: "Go Back Home"), main_app.root_url, class: "home" %>
<div class="version">v<%= Rails.version %></div>
<strong>Our developers have been notified - we're working on it!</strong>
</div>
<% end %>
<% end %>
<% else %>
<%= content_tag :div, details[:description], class: "message" %>
<% end %>
</div>
我尝试重新启动我的 Rails 服务器只是为了确保更改生效,但它仍然不起作用。我错过了什么?