Sha256: 4a443aa88cf8edbfd1abd704908b2e2d0011106f9b74853a26416926c90ee234

Contents?: true

Size: 524 Bytes

Versions: 7

Compression:

Stored size: 524 Bytes

Contents

module Forms
  class PersonForm < Kadmin::Form
    delegate_attributes :gender, :first_name, :last_name, :date_of_birth, :groups

    def initialize(*args)
      super
      raise(ArgumentError, 'Model given should be a person') unless @model.is_a?(Person)
    end

    validate :adult?
    def adult?
      cutoff_date = 18.years.ago.beginning_of_day
      if @model.date_of_birth >= cutoff_date
        @errors.add(:date_of_birth, :invalid, message: 'must be 18 years old')
      end
    end
    private :adult?
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kadmin-0.3.1 test/dummy/lib/forms/person_form.rb
kadmin-0.3.0 test/dummy/lib/forms/person_form.rb
kadmin-0.2.8 test/dummy/lib/forms/person_form.rb
kadmin-0.2.7 test/dummy/lib/forms/person_form.rb
kadmin-0.2.6 test/dummy/lib/forms/person_form.rb
kadmin-0.2.3 test/dummy/lib/forms/person_form.rb
kadmin-0.2.2 test/dummy/lib/forms/person_form.rb