Sha256: 63b938ed9e9ea4fe9e764a931e2e4ad8e2b9737cee9b1abdf70ef7b50b243dd2

Contents?: true

Size: 633 Bytes

Versions: 12

Compression:

Stored size: 633 Bytes

Contents

class PersonForm < Kadmin::Form
  delegate :full_name, to: :model
  delegate_attributes :gender, :first_name, :last_name, :date_of_birth, :groups, group_ids: [:reader]

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

  def group_ids=(ids)
    @model.group_ids = ids.reject(&:blank?).map(&:to_i)
  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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
kadmin-0.6.8 test/dummy/app/forms/person_form.rb
kadmin-0.6.7 test/dummy/app/forms/person_form.rb
kadmin-0.6.6 test/dummy/app/forms/person_form.rb
kadmin-0.6.5 test/dummy/app/forms/person_form.rb
kadmin-0.6.4 test/dummy/app/forms/person_form.rb
kadmin-0.6.3 test/dummy/app/forms/person_form.rb
kadmin-0.6.1 test/dummy/app/forms/person_form.rb
kadmin-0.5.7 test/dummy/app/forms/person_form.rb
kadmin-0.5.6 test/dummy/app/forms/person_form.rb
kadmin-0.4.2 test/dummy/app/forms/person_form.rb
kadmin-0.4.1 test/dummy/app/forms/person_form.rb
kadmin-0.4.0 test/dummy/app/forms/person_form.rb