Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Created July 13, 2011 20:23
Show Gist options
  • Save rkotov93/1081239 to your computer and use it in GitHub Desktop.
Save rkotov93/1081239 to your computer and use it in GitHub Desktop.
User model (sample_app)
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime
# updated_at :datetime
#
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
before_save :encrypt_password
private
def encrypt_password
self.encrypted_password = encrypt(password)
end
def encrypt(string)
string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment