Last active
August 29, 2015 14:28
-
-
Save joaquimadraz/498f61e16c97eff9f6df to your computer and use it in GitHub Desktop.
User model example
This file contains 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
class User < ActiveRecord::Model | |
default_scope { where(state: 'active') } | |
scope :inactive, -> { where(active: false) } | |
validates_presence_of :first_name, :last_name, :email, :password, :invitation_token | |
validates :first_name, length: { minimum: 2 } | |
validates :last_name, length: { minimum: 2 } | |
validates :bio, length: { maximum: 500 } | |
validates :email, uniqueness: true | |
validates :password, length: { in: 6..20 } | |
validates :invitation_token, length: { is: 10 } | |
has_many :posts | |
has_many :comments | |
before_create :assign_object_token | |
before_destroy :last_words | |
def full_name | |
... | |
end | |
private | |
def last_words | |
... | |
end | |
def assign_object_token | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment