这是正确的方式来做一个块救援?最好的方法来做一个救援块
另外,它是最短的吗?
def rescue_definition
begin
user.begin_rescue
rescue Example::ParameterValidationError => e
redirect_to :back, error: e.message_to_purchaser
rescue Example::ProcessingError => e
redirect_to :back, error: e.message_to_purchaser
rescue Example::Error
redirect_to :back, error: e.message_to_purchaser
else
if user
flash['success'] = 'OK'
else
flash['error'] = 'NO'
end
end
redirect_to :back
end
感谢您的回答,我会按照您的建议。另外,我在3次救援中重复'redirect_to:back,error:e.message_to_purchaser'。有没有最短的方法来做到这一点? – Bengala
@Bengala如果这是正确的答案,你应该接受它。 – mysmallidea
因为我们重复“redirect_to:back,error:e.message_to_purchaser”3次,所以我不是正确的答案。我相信它可能会更短。 – Bengala