Files
baclight/app/models/plan.rb
T
2025-12-10 13:22:33 -05:00

18 lines
536 B
Ruby

class Plan < ApplicationRecord
belongs_to :employer_setup_process
has_many :plan_benefits, dependent: :destroy
accepts_nested_attributes_for :plan_benefits, allow_destroy: true, reject_if: :all_blank
after_initialize :create_default_benefits, if: :new_record?
private
def create_default_benefits
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
end
end