Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file added concerns/.keep
Empty file.
23 changes: 23 additions & 0 deletions user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class User < ApplicationRecord
validates :name, presence: true
validates :phone, numericality: true
validates :ngaysinh, presence: true
validate :check_length, :check_ngaysinh, :check_phone
private
def check_length
if self.name && self.name.length < 30
self.errors.add :name, "ten qua ngan"
end
end
def check_ngaysinh
t = Time.now
if self.ngaysinh && (self.ngaysinh.year < t.year - 90 || self.ngaysinh.year > t.year - 7)
self.errors.add :ngaysinh, "khong hop tuoi"
end
end
def check_phone
unless self.phone.length == 10 && self.phone[0] == 0
self.errors.add :phone, "khong hop le"
end
end
end