Exception 中间件中的rails 3.0异常处理
在Rails3.0中,我试图获得中间件代码的异常处理。具体来说,如果请求的内容类型为application/json,但json输入无效,rails当前会呈现public/500.html,这是不幸的Exception 中间件中的rails 3.0异常处理,exception,ruby-on-rails-3,Exception,Ruby On Rails 3,在Rails3.0中,我试图获得中间件代码的异常处理。具体来说,如果请求的内容类型为application/json,但json输入无效,rails当前会呈现public/500.html,这是不幸的 由于这还不在控制器中,所以我看到的大多数事情都不起作用/不适用。您可以从抛出的异常中拯救出来,并决定要做什么: rescue_from Exception, :with => :render_exception def render_exception # examine the Ex
由于这还不在控制器中,所以我看到的大多数事情都不起作用/不适用。您可以从抛出的异常中拯救出来,并决定要做什么:
rescue_from Exception, :with => :render_exception
def render_exception
# examine the Exception here
# and decide which template to render
render :template => "shared/???.html", :status => ???, :layout => 'error'
end
将此代码放在app/controllers/application_controller.rb中
我希望这正是您想要的…您可以从抛出的异常中拯救出来,并决定要做什么:
rescue_from Exception, :with => :render_exception
def render_exception
# examine the Exception here
# and decide which template to render
render :template => "shared/???.html", :status => ???, :layout => 'error'
end
将此代码放在app/controllers/application_controller.rb中
我希望这就是您想要的…您找到解决方案了吗?我也遇到了同样的问题。你找到解决办法了吗?我也有同样的问题。