Conversation
Owner
Author
|
Functionalities:
|
Owner
Author
|
ready |
57fcf03 to
2d4957f
Compare
huongnt-2545
approved these changes
Oct 27, 2023
app/models/user.rb
Outdated
| class User < ApplicationRecord | ||
| before_save { self.email = email.downcase } | ||
|
|
||
| validates :name, presence: true, length: { maximum: 50 } |
There was a problem hiding this comment.
cho các giá trị 50, 255, ... vào file settings nhé
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHAT (optional)
Notes (Kiến thức tìm hiểu thêm)
Uniqueness by Scope
Trong nhiều trường hợp, ta không cần thiết phải thiết lập một trường là duy nhất toàn cục. VD: Tên dự án (Github) của cá nhân chỉ cần là duy nhất đối với từng tài khoản. Xem xét cụ thể hơn thì chính là yêu cầu Unique với một tổ hợp nhiều trường dữ liệu.
VD:
Migration
Migration là công cụ dùng để thay đổi cấu trúc Database
Callback
Callback là các methods gắn vào vòng đời của một object cho phép kiểm soát các thao tác (create, update, destroy) tác động lên object đó. Cụ thể, callback là đoạn mã được kích hoạt trước hoặc sau thao tác thay đổi trạng thái trên object.
VD: Các callbacks được gọi cho các thao tác liên quan đến:
Tạo object:
before_validation,before_save,before_create,...Cập nhật object:
before_validation,before_save,before_update,...Xóa object:
before_destroy,...after_create: Được gọi ngay trước khi lưu object vào DB (save, create).=> có thể rollback, chưa có record.after_save: Được gọi sau khi lưu object vào DB (save, create) nhưng trước khi kết thúc giao dịch => có thể rollback, đã có record.after_commit: Được gọi khi giao dịch đã kết thúc (create, update, destroy) => KHÔNG thể rollback.:on.has_secure_password and BCrypt
has_secure_passworddùng để thêm tính năng xác thực qua password cho Model, cụ thể:XXXvàXXX_confirmation. VD:XXX: passwordXXXvềXXX_digest(sử dụng hàm băm BCrypt) trước khi lưu vào DB.authenticatetrả về Model instance nếu cung cấpXXXchính xác và ngược lại trả về false.Để sử dụng method này, Model cần có trường
XXX_digest