1
以下のような良い方法がありますか?Rubyの異なるif条件で異なるエラーメッセージのベースを印刷する方が良い
if promo_code.present?
if promo_code.active?(self)
if !promo_code.expired?(self)
if promo_code.applicable?(self)
current_customer.promo_transactions.create!(promo_code: promo_code, order_id: id)
else
return false
end
else
errors.add(:promo_code, message: 'Sorry! This code has expired')
return false
end
else
errors.add(:promo_code, message: 'Sorry! This code cannot be used at this time.')
return false
end
else
errors.add(:promo_code, message: 'Sorry! The code does not exist. Check for typos')
return false
end
いずれかの条件が満たされない場合は、falseと特定のエラーメッセージを返す必要があります。私が持っているやり方はかわいそうだと思うし、これを行う良い方法があるのだろうか?