Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails异常处理程序gem_Ruby On Rails_Ruby_Exceptionhandler - Fatal编程技术网

Ruby on rails Rails异常处理程序gem

Ruby on rails Rails异常处理程序gem,ruby-on-rails,ruby,exceptionhandler,Ruby On Rails,Ruby,Exceptionhandler,我已经安装了Rails并尝试按照说明设置自定义错误处理,但是我仍然收到gem创建的标准500错误消息: 500内部服务器错误 如果您是本网站的管理员 请阅读此web应用程序的日志文件和/或 web服务器的日志文件,以查找出了什么问题 下面是我添加到config/application.rb的内容: class Application < Rails::Application config.exception_handler = { dev: true, layo

我已经安装了Rails并尝试按照说明设置自定义错误处理,但是我仍然收到gem创建的标准500错误消息:

500内部服务器错误

如果您是本网站的管理员 请阅读此web应用程序的日志文件和/或 web服务器的日志文件,以查找出了什么问题

下面是我添加到
config/application.rb
的内容:

class Application < Rails::Application
  config.exception_handler = {
      dev: true,
      layouts: {
        '500' => 'exception'
      }
  }
end
<!DOCTYPE html>
<html>
  <head>
    <title><%= "Error - #{@exception.status} Error" %></title>
  </head>

  <body>

    <div class="container">
      <%= yield %>
    </div>

  </body>
</html>
并使用以下命令生成默认异常视图:
rails generate exception\u 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>

错误
v
我们的开发者已经得到通知-我们正在努力

我尝试重新启动rails服务器,只是为了确保更改生效,但仍然不起作用。我错过了什么?

在版本异常处理程序0.8.0.0的config/application.rb中

config.exception_handler = {
dev: nil, # allows you to turn ExceptionHandler "on" in development
db:nil, # allocates a "table name" into which exceptions are saved (defaults to nil)
email: "", # sends exception emails to a listed email (string // "you@email.com")

  # Custom Exceptions
  custom_exceptions: {
    #'ActionController::RoutingError' => :not_found # => example
  },

  # On default 5xx error page, social media links included
  social: {        
    facebook: nil, # Facebook page name   
    twitter:  nil, # Twitter handle  
    youtube:  nil, # Youtube channel name / ID
    linkedin: nil, # LinkedIn name
    fusion:   nil  # FL Fusion handle
  },  

  # This is an entirely NEW structure for the "layouts" area
  # You're able to define layouts, notifications etc ↴

  # All keys interpolated as strings, so you can use symbols, strings or integers where necessary
  exceptions: {

    :all => {
      layout: "exception", # define layout
      notification: true # (false by default)
  # action: ____, (this is general)
  # background: (can define custom background for exceptions layout if required)
    },
    404 => {
      layout: "exception", # define layout
      notification: true # (false by default)
  # action: ____, (this is general)
  # background: (can define custom background for exceptions layout if required)
    },    
    500 => {
      layout: "exception", # define layout
      notification: true # (false by default)
  # action: ____, (this is general)
  # background: (can define custom background for exceptions layout if required)
    }

    # This is the old structure
    # Still works but will be deprecated in future versions

    # 501 => "exception",
    # 502 => "exception",
    # 503 => "exception",
    # 504 => "exception",
    # 505 => "exception",
    # 507 => "exception",
    # 510 => "exception"

  }
}

您是否查看了日志文件错误是什么?可能是这个gem无法处理的错误。您的
config/development.rb
中确实有
配置。请考虑所有请求\u local=true
,对吗?PS:我假设您正在dev env上测试此功能。@AlexandreAngelim yes@slowjack2k似乎正在尝试使用我的默认布局
application.html.erb
,而不是
exception.html.erb
在299ms内完成了500个内部服务器错误故障保护响应期间的错误:未定义的方法
each'for nil:NilClass/Users/godzilla74/Coding/neo-api/app/views/layouts/\u-navigation.html.erb:38:in
\u-app\u-view\u-layouts\u-navigation\u-html\u-html\u-erb\u-2393195447720129\u-70250216188520'
应将
'500'=>'exception'
更改为
500=>'exception'
(键500-是整数而不是字符串)