Permalink
Browse files

Add before_validation email downcase filter

  • Loading branch information...
1 parent bbe22eb commit 8b519cc175b24cab4c529c1ff19c631dea4e703c @mhartl mhartl committed Apr 18, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 app/models/user.rb
View
@@ -9,11 +9,13 @@ class User < ActiveRecord::Base
dependent: :destroy
has_many :followers, through: :reverse_relationships, source: :follower
+ before_validation { |user| user.email = email.downcase }
before_save :create_remember_token
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
- validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }
+ validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
+ uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
validates :password_confirmation, presence: true

0 comments on commit 8b519cc

Please sign in to comment.