यह मेरी पहली पोस्ट है, इसलिए मुझे आशा है कि मैं इस प्रश्न को सही जगह पर पोस्ट कर रहा हूं। अन्यथा, कृपया मुझे बताएं ताकि अगली बार जब मैं यहां पोस्ट करूं :)रेल पर रूबी -एचटीटीपी त्रुटि हैंडलिंग
मैं एक आरओआर वेबसाइट पर काम कर रहा हूं और व्यक्तिगत रूप से सर्वर त्रुटियों (400, 404, 500, आदि) को संभालना चाहता हूं। साथ ही, चूंकि वेबसाइट गतिशील है, इसलिए मैं सर्वर स्तर की बजाय रेल पर्यावरण के भीतर त्रुटियों को संभालना चाहता हूं। मैं जो करना चाहता हूं उसका एक उदाहरण वैकल्पिक सामग्री या खोज बार के साथ उपयोगकर्ता को प्रस्तुत करना हो सकता है जब वह उस पृष्ठ या टेम्पलेट में टक्कर लगी जो लोड नहीं होगी या बस अस्तित्व में नहीं है।
मैं आरओआर में नया हूं इसलिए अगर मैं स्पष्ट पूछ रहा हूं तो कृपया मेरे साथ बेकार रहें।
तो, मैंने कुछ पढ़ा और मुझे लगता है कि बचाव_फॉर्म अपवाद हैंडलर का उपयोग करना मेरे मामले में जाने का तरीका है। (यदि आप में से कोई भी अलग राय है तो सुनकर खुशी होगी)।
मैं एक साधारण कार्यशील प्रोटोटाइप है (नीचे दिए गए कोड को देखें) और चल रहा है, तथापि, मैं कोई त्रुटि मिलती है जब मैं कोड के लिए निम्न अपवाद संचालक शामिल हैं:
rescue_from ActionController::MissingTemplate, :with => :not_found #404
अब, मैं नहीं देख सकते हैं कि मेरे पास वर्तनी त्रुटि है और मैंने इस लाइन को वेब पर पोस्ट कोड में देखा है। हालांकि, जब मैं इसे शामिल मैं निम्नलिखित मार्ग त्रुटि मिलती है:
Routing Error No route matches "/errorhandle" with {:method=>:get}
मैं रेल 2.3.5 पर काम कर रहा हूँ, शायद यह है कि यह साथ क्या करने के लिए कुछ मिल गया है?
मुझे आशा है कि आप इस मुद्दे पर कुछ प्रकाश डालने में मेरी सहायता कर सकते हैं।
चीयर्स! /माजा
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery #See ActionController::RequestForgeryProtection for details
#ActiveRecord exceptions
rescue_from ActiveRecord::RecordNotFound, :with => :not_found #400
#ActiveResource exceptions
rescue_from ActiveResource::ResourceNotFound, :with => :not_found #404
#ActionView exceptions
rescue_from ActionView::TemplateError, :with => :not_found #500
#ActionController exceptions
rescue_from ActionController::RoutingError, :with => :not_found #404
rescue_from ActionController::UnknownController, :with => :not_found #404
rescue_from ActionController::MethodNotAllowed, :with => :not_found #405
rescue_from ActionController::InvalidAuthenticityToken, :with => :not_found #405
rescue_from ActionController::UnknownAction, :with => :not_found #501
# This particular exception causes all the rest to fail.... why?
# rescue_from ActionController::MissingTemplate, :with => :not_found #404
protected
def not_found
render :text => "Error", :status => 404
end
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
end
क्या आप हमें रूट.आरबी से प्रासंगिक मार्ग दिखा सकते हैं, यदि कोई हो? – Trevoke
निश्चित ट्रेवोक, त्वरित उत्तर के लिए धन्यवाद। मैंने रूट.आरबी में कुछ भी नहीं जोड़ा है, इसलिए मुझे लगता है कि यह बहुत अधिक std है। फ़ाइल: एक्शनकंट्रोलर :: रूटिंग :: Routes.draw do | map | map.resources: errorhandlers # ... बाहर टिप्पणी की # लाइनों की # बहुत सारे ... map.connect ': नियंत्रक /: कार्रवाई /: आईडी' map.connect ': नियंत्रक /: कार्रवाई/: आईडी।: प्रारूप ' अंत –
ओह, यह सुनिश्चित न करें कि टिप्पणी को कैसे अच्छा और साफ * uark * दिखाना है। आशा है कि यह किसी भी तरह से पठनीय है ... –