Skip to content

Instantly share code, notes, and snippets.

@joaquimadraz
Last active August 29, 2015 14:28
Show Gist options
  • Save joaquimadraz/498f61e16c97eff9f6df to your computer and use it in GitHub Desktop.
Save joaquimadraz/498f61e16c97eff9f6df to your computer and use it in GitHub Desktop.
User model example
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