【问题标题】:Having trouble with custom errors pages in Rails 4在 Rails 4 中遇到自定义错误页面的问题
【发布时间】:2015-11-17 05:09:01
【问题描述】:

似乎无法正常工作...仍然显示默认错误页面...

使用 RAILS 4

这是我的代码..

错误控制器

def not_found
  render :status => 404
end

def unacceptable
  render :status => 422
end

def internal_error
  render :status => 500
end

应用程序.rb

config.exceptions_app = self.routes

Routes.rb

match "/404", :to => "errors#not_found", via: 'get'
match "/422", :to => "errors#unacceptable", via: 'get'
match "/500", :to => "errors#internal_error", via: 'get'

我对所有这些文件都有适当的看法

为什么它仍然呈现默认的 rails 错误消息?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 http-status-code-404


    【解决方案1】:

    你可以去 config/environments/development.rb 修改下面这行,

    config.consider_all_requests_local = true
    

    config.consider_all_requests_local = false
    

    虽然我自己没有尝试过,但它应该在开发时启用错误消息。默认允许您查看调试模式。

    【讨论】:

      【解决方案2】:

      还要注意错误页面不会显示在:development 环境中

      【讨论】:

      • 但是如果你在开发环境中访问 localhost:300/404 它将呈现错误页面...我知道你无法通过它们的预期目的访问它们(访问错误的 url)跨度>
      • 为什么会这样?造型难吗??猜猜我只是制作一个随机页面并对其进行样式设置,然后将代码转移到错误页面大声笑 LAME 谢谢@dtt101
      • 或者可能是因为路由错误页面在开发时更有用? :P
      猜你喜欢
      • 2013-09-06
      • 2011-01-15
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多