class User < ActiveRecord::Base
  has_secure_password
  validates :username, :email, presence: true
  validates :email, uniqueness: true
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create

  has_many :questions
  has_many :answers
  has_many :votes
  has_many :comments

end

class User < ActiveRecord::Base
  has_secure_password
  validates :username, :email, presence: true
  validates :email, uniqueness: true

  has_many :questions
  has_many :answers
  has_many :votes
  has_many :comments
  
end

--- 
+++ 
@@ -2,10 +2,11 @@
   has_secure_password
   validates :username, :email, presence: true
   validates :email, uniqueness: true
+  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
 
   has_many :questions
   has_many :answers
   has_many :votes
   has_many :comments
-  
+
 end
Add validation to put a format constraint on email attribute in User class
