[英]rescue_from doesn't catch an error
class MyController < ApplicationController
before_action :set_data, only: [:show, :edit, :update, :destroy]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_data
respond_to :html
def show
respond_with(@item)
end
private
def set_data
@item = Item.find params[:id]
end
def invalid_data
logger.log "Error, id: #{params[:id]}"
redirect_to some_url, error: 'Error123'
end
end
Still, when I go to my/123
or my/123fdsfds
or my/fdsfds
, I get a standard "error" screen: 不过,当我转到my/123
或my/123fdsfds
或my/fdsfds
,我得到一个标准的“错误”屏幕:
ArgumentError in MyController#show
comparison of String with 0 failed
logger.log "Error, id: #{params[:id]}"
redirect_to some_url, error: 'Error123'
end
end
and I don't get redirected. 而且我不会被重定向。 How come? 怎么会?
我原来,looger.log本身引起了错误,应该是:
logger.log Logger::ERROR, "Error, id: #{params[:id]}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.