婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Rails中遇到錯誤跳轉到統一提示錯誤頁的方法

Rails中遇到錯誤跳轉到統一提示錯誤頁的方法

熱門標簽:天津外呼系統怎么收費 巫師3地圖標注魔力之所 AI電銷機器人 線路 漯河電銷 柯城手機地圖如何做地圖標注 淮安自動外呼系統供應商 中牟外呼系統違法嗎 征服者企業地圖標注 外呼線路從哪里出來的

一個迭代開發中的網站難免存在bug,出bug的時候客戶體驗就很不好了,為解決此問題,可以在class error產生的時候,觸發跳轉到統一提示頁面,并給開發人員發郵件報錯誤信息,提高測試能力和用戶體驗。以下是核心方法;在ApplicationController中添加如下代碼,不同rails版本的class error略有變化。

復制代碼 代碼如下:

AR_ERROR_CLASSES = [ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid] 
  ERROR_CLASSES = [NameError, NoMethodError, RuntimeError, 
         ActionView::TemplateError, 
         ActiveRecord::StaleObjectError, ActionController::RoutingError, 
         ActionController::UnknownController, AbstractController::ActionNotFound, 
         ActionController::MethodNotAllowed, ActionController::InvalidAuthenticityToken] 
 
  ACCESS_DENIED_CLASSES = [CanCan::AccessDenied] 
 
  if Rails.env.production? 
    rescue_from *AR_ERROR_CLASSES, :with => :render_ar_error 
    rescue_from *ERROR_CLASSES, :with => :render_error 
    rescue_from *ACCESS_DENIED_CLASSES, :with => :render_access_denied 
  end 
   
  #called by last route matching unmatched routes.  Raises RoutingError which will be rescued from in the same way as other exceptions. 
 
#備注rails3.1后ActionController::RoutingError在routes.rb中最后加如下代碼才能catch了。 
#rails3下:match '*unmatched_route', :to => 'application#raise_not_found!' 
#rails4下:get '*unmatched_route', :to => 'application#raise_not_found!' 
 
  def raise_not_found! 
    raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}") 
  end 
 
  def render_ar_error(exception) 
    case exception 
    when *AR_ERROR_CLASSES then exception_class = exception.class.to_s 
    else exception_class = 'Exception' 
    end 
 
    send_error_email(exception, exception_class) 
  end 
 
  def render_error(exception) 
    case exception 
    when *ERROR_CLASSES then exception_class = exception.class.to_s 
    else exception_class = 'Exception' 
    end 
 
    send_error_email(exception, exception_class) 
  end 
 
  def render_access_denied(exception) 
    case exception 
    when *ACCESS_DENIED_CLASSES then exception_class = exception.class.to_s 
    else exception_class = "Exception" 
    end 
 
    send_error_email(exception, exception_class) 
  end

標簽:甘孜 內江 棗莊 西雙版納 大慶 河池 南昌 克拉瑪依

巨人網絡通訊聲明:本文標題《Rails中遇到錯誤跳轉到統一提示錯誤頁的方法》,本文關鍵詞  Rails,中,遇到,錯誤,跳,轉到,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Rails中遇到錯誤跳轉到統一提示錯誤頁的方法》相關的同類信息!
  • 本頁收集關于Rails中遇到錯誤跳轉到統一提示錯誤頁的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 连城县| 沙雅县| 凤台县| 雷波县| 车致| 额敏县| 察隅县| 宝坻区| 神农架林区| 乌拉特中旗| 湘潭县| 肇州县| 房产| 措美县| 旅游| 兰考县| 宽甸| 迁安市| 沁源县| 措美县| 石河子市| 东丰县| 缙云县| 噶尔县| 丰台区| 乳源| 隆昌县| 仁怀市| 新丰县| 婺源县| 来凤县| 崇明县| 新营市| 阿合奇县| 景德镇市| 合江县| 同德县| 浮山县| 怀柔区| 勃利县| 商丘市|