标签:io ar cti res app ef 404 rom
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、其他等等错误页面,可以写到一个方法中
def self.rescue_errors rescue_from Exception, with: :render_error rescue_from RuntimeError, with: :render_error rescue_from ActionController::UnknownController, with: :render_not_found rescue_from ActionController::UnknownAction, with: :render_not_found end rescue_errors unless Rails.env.development?
rails resce_from设置错误页面,布布扣,bubuko.com
标签:io ar cti res app ef 404 rom
原文地址:http://my.oschina.net/fxhover/blog/298559