Created
January 20, 2013 06:53
-
-
Save hoandang/4577046 to your computer and use it in GitHub Desktop.
A typical user model in rails
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
# 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