আমি ব্যতিক্রম উত্থাপিত হয় যখন একটি কাস্টম ত্রুটি পৃষ্ঠা প্রদর্শন করতে এটি ব্যবহার।
rescue_from Exception do |exception|
logger.error exception.class
logger.error exception.message
logger.error exception.backtrace.join "\n"
@exception = exception
# ExceptionNotifier::Notifier.exception_notification env, @exception
respond_to do |format|
if [AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, ActionController::RoutingError, ActionController::UnknownAction].include?(exception.class)
format.html { render :template => "errors/404", :status => 404 }
format.js { render :nothing => true, :status => 404 }
format.xml { render :nothing => true, :status => 404 }
elsif exception.class == CanCan::AccessDenied
format.html {
render :template => "errors/401", :status => 401 #, :layout => 'application'
}
# format.js { render :json => { :errors => [exception.message] }, :status => 401 }
# format.js { render :js => 'alert("Hello 401")' }
format.js { render :template => 'errors/401.js.erb' }
else
ExceptionNotifier::Notifier.exception_notification(env, exception).deliver
format.html { render :template => "errors/500", :status => 500 } #, :layout => 'im2/application' }
# format.js { render :nothing => true, :status => 500 }
format.js { render :template => 'errors/500.js.erb' }
end
end
end
e.backtrace। আমি যে প্রকল্পগুলির সাথে কাজ করছি তার একটিতে আমি এটি দেখেছি। সর্বোত্তম পদ্ধতির নয়, তবে এটি কার্যকর। তবে অন্য কারও কাছ থেকে আরও ভাল সমাধান শোনার আশা করি।