62 lines
1.9 KiB
Ruby
62 lines
1.9 KiB
Ruby
class EmployerSetupForm
|
|
include ActiveModel::Model
|
|
include ActiveModel::Attributes
|
|
|
|
attribute :current_step, :string, default: "general"
|
|
attribute :name, :string
|
|
attribute :employer_logo
|
|
attribute :group_number, :string
|
|
attribute :pl_plan_key, :string
|
|
attribute :effect_date, :string
|
|
attribute :number_of_plans, :integer
|
|
attribute :network, :string
|
|
attribute :number_of_additional_network_logos, :integer
|
|
attribute :plans, array: true, default: -> { [] }
|
|
# attribute :benefit_descs, :hash, default: -> { {} }
|
|
attribute :network_exceptions, array: true, default: -> { [] }
|
|
|
|
attr_accessor :benefit_descs
|
|
|
|
# Define validations based on the current step
|
|
with_options on: :general_info do
|
|
validates :name, presence: true
|
|
validates :employer_logo, presence: true
|
|
validates :group_number, presence: true
|
|
validates :pl_plan_key, presence: true
|
|
validates :effect_date, presence: true
|
|
validates :number_of_plans, presence: true
|
|
validates :network, presence: true
|
|
# validates :number_of_additional_network_logos, presence: true if network = "cigna+"
|
|
end
|
|
|
|
with_options on: :plan_info do
|
|
validates :plans, presence: true
|
|
# validates :benefit_descs, presence: true
|
|
end
|
|
|
|
with_options on: :network_info do
|
|
# validates :network_exceptions, presence: true if number_of_additional_network_logos > 0
|
|
end
|
|
|
|
# def initialize(params = {})
|
|
# super(params)
|
|
# # Ensure the attribute is a hash after initialization
|
|
# @benefit_descs = params[:benefit_descs].to_h if params[:benefit_descs]
|
|
# end
|
|
|
|
def benefit_descs
|
|
@benefit_descs ||= {}
|
|
end
|
|
|
|
def save
|
|
# Implement logic to save data to models after all steps are complete
|
|
# For example, create a User record with the collected data
|
|
if valid? && step == total_steps
|
|
# User.create!(name: name, email: email, password: password)
|
|
true
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
end |