【发布时间】:2016-01-13 23:54:20
【问题描述】:
我正在将动态错误页面实现到应用程序中,并且感觉它在 public 文件夹中查找(现在不存在的)模板,而不是遵循我设置的路线。
在config/application.rb 中,我添加了config.exceptions_app = self.routes 行来说明这一点。
然后我将以下内容添加到我的路线中:
get "/not-found", :to => "errors#not_found"
get "/unacceptable", :to => "errors#unacceptable"
get "/internal-error", :to => "errors#internal_error"
错误控制器如下所示:
class ErrorsController < ApplicationController
layout 'errors'
def not_found
render :status => 404
end
def unacceptable
render :status => 422
end
def internal_error
render :status => 500
end
end
转到/not-found 会显示应有的模板,但访问任何不存在的 URL(即 /i-dont-exist)会呈现一个空白页面。
我能看到的唯一原因是异常处理需要路由,例如,get "/404", :to => "errors#not_found",但具有讽刺意味的是,它没有找到 /404 的路由(不,不仅仅是它工作:))。
任何建议,不胜感激。谢谢,史蒂夫。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 configuration routing