1、设置ActiveRecord find方法没找到不报错,调用一个显示404页面的方法
class ApplicationController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found def record_not_found render 'record_not_found' # .... true end end
2、设置500页面
rescue_from RuntimeError, with: :render_error def render_error render 'error_500', status: 500, layout: 'public' end
3、其他等等错误页面,可以写到一个方法中
rescue_from Exception, with: :render_error unless Rails.env.development? rescue_from RuntimeError, with: :render_error unless Rails.env.development? rescue_from ActionController::UnknownController, with: :render_not_found unless Rails.env.development? rescue_from ActionController::UnknownAction, with: :render_not_found unless Rails.env.development?