update employee

This commit is contained in:
Thein Lin Kyaw
2020-01-29 16:07:11 +06:30
parent 11ffaa738f
commit 05f71de9f9

View File

@@ -12,7 +12,11 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
before_save :generate_app_id, :generate_app_token , if: Proc.new { self.role == "application" }
before_create :generate_app_id, :generate_app_token,
if: Proc.new { self.role == "application" }
before_update :generate_app_id, :generate_app_token,
if: Proc.new { self.role == "application" && self.role_was != "application" }
# Employee Image Uploader
mount_uploader :image_path, EmployeeImageUploader
@@ -90,14 +94,13 @@ class Employee < ApplicationRecord
end
def generate_app_id
return if self.app_id.present?
self.app_id = SecureRandom.hex(8)
rescue ActiveRecord::RecordNotUnique
retry
end
def generate_app_token
self.app_token = SecureRandom.hex(8)
self.app_token = SecureRandom.hex(10)
rescue ActiveRecord::RecordNotUnique
retry
end