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

主頁(yè) > 知識(shí)庫(kù) > Rails中遇到錯(cuò)誤跳轉(zhuǎn)到統(tǒng)一提示錯(cuò)誤頁(yè)的方法

Rails中遇到錯(cuò)誤跳轉(zhuǎn)到統(tǒng)一提示錯(cuò)誤頁(yè)的方法

熱門(mén)標(biāo)簽:天津外呼系統(tǒng)怎么收費(fèi) 巫師3地圖標(biāo)注魔力之所 AI電銷(xiāo)機(jī)器人 線路 漯河電銷(xiāo) 柯城手機(jī)地圖如何做地圖標(biāo)注 淮安自動(dòng)外呼系統(tǒng)供應(yīng)商 中牟外呼系統(tǒng)違法嗎 征服者企業(yè)地圖標(biāo)注 外呼線路從哪里出來(lái)的

一個(gè)迭代開(kāi)發(fā)中的網(wǎng)站難免存在bug,出bug的時(shí)候客戶體驗(yàn)就很不好了,為解決此問(wèn)題,可以在class error產(chǎn)生的時(shí)候,觸發(fā)跳轉(zhuǎn)到統(tǒng)一提示頁(yè)面,并給開(kāi)發(fā)人員發(fā)郵件報(bào)錯(cuò)誤信息,提高測(cè)試能力和用戶體驗(yàn)。以下是核心方法;在ApplicationController中添加如下代碼,不同rails版本的class error略有變化。

復(fù)制代碼 代碼如下:

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

標(biāo)簽:甘孜 內(nèi)江 棗莊 西雙版納 大慶 河池 南昌 克拉瑪依

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Rails中遇到錯(cuò)誤跳轉(zhuǎn)到統(tǒng)一提示錯(cuò)誤頁(yè)的方法》,本文關(guān)鍵詞  Rails,中,遇到,錯(cuò)誤,跳,轉(zhuǎn)到,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Rails中遇到錯(cuò)誤跳轉(zhuǎn)到統(tǒng)一提示錯(cuò)誤頁(yè)的方法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Rails中遇到錯(cuò)誤跳轉(zhuǎn)到統(tǒng)一提示錯(cuò)誤頁(yè)的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 湄潭县| 三河市| 台东县| 呼和浩特市| 苏尼特右旗| 平遥县| 荥经县| 于都县| 博客| 科技| 财经| 泽库县| 沂源县| 闵行区| 东乡县| 德钦县| 昂仁县| 临潭县| 德令哈市| 南安市| 右玉县| 上犹县| 巨野县| 白山市| 三江| 晋中市| 犍为县| 什邡市| 福鼎市| 阿合奇县| 尚义县| 汉寿县| 古田县| 凤翔县| 方城县| 梅州市| 兴山县| 万全县| 岫岩| 泾川县| 新蔡县|