From 9064a37e24110189396f8c179864568239c814b8 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 5 Oct 2014 18:26:30 +0200 Subject: [PATCH] Validate email format --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0d33bfa..05cfd37 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,11 +11,12 @@ class User < ActiveRecord::Base has_many :comments, :dependent => :destroy has_many :expiring_tokens, dependent: :destroy + validates :email, presence: true, on: :update + validates :email, format: { with: /.+@.+\..+/i }, uniqueness: true, if: :email validates :username, uniqueness: { case_sensitive: false }, format: { with: USERNAME_FORMAT }, length: { minimum: 2, maximum: 16 }, if: :username - validates :email, uniqueness: true, if: :email scope :with_username, -> { where('username IS NOT NULL') }