我正在尝试在我的网站上设置自定义错误页面.我正在遵循
PerfectLine Blog的准则.
它在控制器存在的情况下起作用,但该ID不存在.例如,我有一个博客控制器,id 4不存在.它显示自定义错误页面
但是在控制器本身不存在的情况下不存在.例如,如果我键入一些带有数字ID的随机控制器不被我在应用程序控制器中设置的方法所捕获,以重新路由自定义错误页面.在这种情况下,我得到一个
ActionController :: RoutingError(无路由匹配“/ randomcontrollername”):
application_controller.rb
- class ApplicationController < ActionController::Base
- protect_from_forgery
- unless Rails.application.config.consider_all_requests_local
- rescue_from Exception,:with => :render_error
- rescue_from ActiveRecord::RecordNotFound,:with => :render_not_found
- rescue_from ActionController::RoutingError,:with => :render_not_found
- rescue_from ActionController::UnknownController,:with => :render_not_found
- rescue_from ActionController::UnknownAction,:with => :render_not_found
- end
- private
- def render_not_found(exception)
- render :template => "/error/404.html.erb",:status => 404
- end
- def render_error(exception)
- render :template => "/error/500.html.erb",:status => 500
- end
- end
你可以帮我吗.谢谢.