Skip to content

Instantly share code, notes, and snippets.

@ricoSaw
Last active December 14, 2015 08:49
Show Gist options
  • Save ricoSaw/5060229 to your computer and use it in GitHub Desktop.
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.
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