Major features finished
This commit is contained in:
@@ -4,19 +4,27 @@ module IdCard
|
||||
has_many :field_exception_items, dependent: :destroy
|
||||
accepts_nested_attributes_for :field_exception_items, allow_destroy: true, reject_if: :all_blank
|
||||
|
||||
VALID_TYPES = ['zipcode', 'state', 'family_id']
|
||||
serialize :exception_values, coder: JSON
|
||||
|
||||
VALID_TYPES = ['family_id', 'zipcode', 'state'].freeze
|
||||
|
||||
before_validation :format_exception_values, if: :exception_values_changed?
|
||||
|
||||
validates :exception_type, inclusion: { in: VALID_TYPES,
|
||||
message: "%{value} is not a valid exception type" }
|
||||
|
||||
|
||||
def to_card_attrs
|
||||
self.field_exception_items.map(&:card_attrs).reduce({}, :merge)
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
def permitted_params(params)
|
||||
params.require(:id_card_setup).permit(
|
||||
field_exceptions_attributes: [
|
||||
:exception_type,
|
||||
:exception_value,
|
||||
:exception_values,
|
||||
:_destroy,
|
||||
field_exception_items_attributes: [
|
||||
:field_name,
|
||||
@@ -31,5 +39,13 @@ module IdCard
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_exception_values
|
||||
if self.exception_values.is_a?(String)
|
||||
self.exception_values = self.exception_values.split(",").map(&:strip)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user