You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
class Users::UpdateAccountForm
|
|
include ActiveModel::Model
|
|
|
|
attr_accessor :user
|
|
attr_accessor :nickname, :name, :show_realname, :gender, :location, :location_city,
|
|
:identity, :student_id, :technical_title, :school_id, :department_id
|
|
|
|
validates :nickname, presence: true
|
|
validates :name, presence: true
|
|
validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] }
|
|
validates :location, presence: true
|
|
validates :location_city, presence: true
|
|
validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] }
|
|
validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' }
|
|
validates :student_id, presence: true, if: -> { identity.to_s == 'student' }
|
|
validates :school_id, presence: true
|
|
|
|
validate :check_school_exist
|
|
def check_school_exist
|
|
return if school_id.blank?
|
|
unless School.exists?(id: school_id)
|
|
errors.add(:school_id, :not_exist)
|
|
end
|
|
end
|
|
|
|
validate :check_department_exist
|
|
def check_department_exist
|
|
return if department_id.blank?
|
|
unless Department.exists?(id: department_id)
|
|
errors.add(:department_id, :not_exist)
|
|
end
|
|
end
|
|
end |