Sha256: 3a4470d914cd7c97a65ae2faf53ba87fac6c1c18964fa0403ef45d7dbd0ce49a

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Account
  class MailingForm < ApplicationForm
    attribute :receive_notifications, Boolean
    attribute :attachments_via_email, Boolean
    attribute :letter_types_ids,      Array[Integer]

    # validates :receive_notifications, presence: true
    # validates :attachments_via_email, presence: true
    # validates :allowed_letter_types_ids, presence: true
    # validate :valid_letter_types

    def update(params = {})
      self.attributes = params.reverse_merge(attributes)
    end

    def submit
      return false unless valid?

      api_answer = TranslationCms::Api::Customers::Notification.create(attributes)
      merge_responce! api_answer
      errors.empty?
    end

    protected

    def submit_params(params)
      if params[:letter_types_ids].is_a?(Array)
        params[:letter_types_ids] = params[:letter_types_ids].join(',')
      end
      params
    end

    def valid_letter_types?
      # errors.add(:country_code, :invalid) if ISO3166::Country.find_country_by_alpha3(country_code).nil?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/forms/account/mailing_form.rb