Skip to content

Instantly share code, notes, and snippets.

@hoandang
Created January 20, 2013 06:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoandang/4577046 to your computer and use it in GitHub Desktop.
Save hoandang/4577046 to your computer and use it in GitHub Desktop.
A typical user model in rails
# Gem 'bcrypt-ruby'
# Generate User model with password_digest field
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :name, :password, :password_confirmation
before_save { self.email.downcase! }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, uniqueness: {case_sensitive: false},
length: {maximum: 50}, format: { with: VALID_EMAIL_REGEX }
validates :name, presence: true, uniqueness: true
validates :password, length: {minimum: 5}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment