你好我的代码在这里
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from Exception, :with => :error_render_method
def error_render_method
respond_to do |type|
type.html { render :template => "web/static/missing", :status => 404 }
type.all { render :nothing => true, :status => 404 }
end
true
end
end
它工作正常,但如果发生任何错误我也想在日志中打印我该怎么做
最佳答案
使用logger.warn
:
rescue_from Exception do |exception|
error_render_method(exception)
end
def error_render_method(error)
logger.warn(error.message)
respond_to do |type|
type.html { render :template => "web/static/missing", :status => 404 }
type.all { render :nothing => true, :status => 404 }
end
true
end
关于ruby-on-rails - 如果我在应用程序 Controller 中处理错误,则在日志中打印异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24163992/