obdev/app/models/form.rb

23 lines
779 B
Ruby
Raw Normal View History

class Form < ApplicationRecord
# Assuming each form can have many onboarding items associated with different owners.
has_many :onboarding_items
validates :name, presence: true
validates :role, inclusion: { in: %w[Participant Worker Vendor Employer] }
# Include more validations as necessary
after_save :update_onboarding_items
private
def update_onboarding_items
# Dynamically find the model class based on the role. Ensure 'role' matches your model name exactly.
owner_class = role.constantize
# For each instance of the model, find or create an onboarding item linked to this form.
owner_class.find_each do |owner|
OnboardingItem.find_or_create_by(owner: owner, form: self)
end
end
end