Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Conditionally skip email validation. #545

wants to merge 1 commit into from

2 participants


There are some cases in which you might not want to force the presence of an email (for example when using Oauth with a twitter account) so it becomes kinda handy to simply define a method like this one in the model:

def email_required?

and skip the email presence validation, while keeping the Validatable module intact.

It's just a little contribution but i hope you find it useful.


Sounds good, but e-mail required should be a protected method.


It's actually a protected method, check the full file email_required? it's right under password_required? right under the protected declaration.


I forgot the documentation thou :P


Something like this could be :)

# Checks whether an email is needed or not. For validations only.
# Always return true, but can be overridden in your model 
# to skip the email presence validation, for example:
# If you are also using Oauth and you don't need the email.

Sorry, my bad, merged!

@ledowong ledowong referenced this pull request

email_required? #2157

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2010
  1. @sagmor
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/devise/models/validatable.rb
6 lib/devise/models/validatable.rb
@@ -22,7 +22,7 @@ def self.included(base)
base.class_eval do
- validates_presence_of :email
+ validates_presence_of :email, :if => :email_required?
validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :case_sensitive => false, :allow_blank => true
validates_format_of :email, :with => email_regexp, :allow_blank => true
@@ -52,6 +52,10 @@ def password_required?
!persisted? || !password.nil? || !password_confirmation.nil?
+ def email_required?
+ true
+ end
module ClassMethods
Devise::Models.config(self, :email_regexp, :password_length)
Something went wrong with that request. Please try again.