Skip to content

Instantly share code, notes, and snippets.

View rib3ye's full-sized avatar
🆒
Petting a cat

Noah Tsutsui rib3ye

🆒
Petting a cat
View GitHub Profile
@hoandang
hoandang / ruby: user.rb
Created January 20, 2013 06:53
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