Last active
December 14, 2015 08:48
-
-
Save ricoSaw/5060023 to your computer and use it in GitHub Desktop.
# Möglichkeit 1
Die Validierung aus den plan_addition in plan zu verlagern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Plan < ActiveRecord::Base | |
has_many :plan_additions | |
... | |
after_validation do | |
plan_additions.each do |plan_addition| | |
# hier könnte eine andere, bessere Validierung in plan_addition model gepackt werden | |
if plan_addition.monthly_price.blank? | |
plan_addition.errors.add(:monthly_price, :blank) | |
# Der Einfachheit halber, habe ich die Fehlermeldung als base error verpackt. | |
# Besser wäre die generierten errors aus plan_addition.errors und errors zu mergen. | |
errors.add :base, I18n.translate('plan_addition_monthly_price_cant_be_blank') | |
end | |
end if monthly_price? | |
errors.empty? | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment