Last active
December 14, 2015 08:49
-
-
Save ricoSaw/5060229 to your computer and use it in GitHub Desktop.
# Möglichkeit 2
Wohl die bessere Lösung mit inverse_of und validates_associated.
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, :inverse_of => :plan | |
validates_associated :plan_additions | |
accepts_nested_attributes_for :plan_additions | |
... | |
end | |
class PlanAddition < ActiveRecord::Base | |
... | |
belongs_to :plan | |
validates :name, :presence => true | |
validates :monthly_price, presence: { if: -> { plan.monthly_price? } } | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment