Skip to content

Conditionally skip email validation. #545

Closed
wants to merge 1 commit into from

2 participants

@sagmor
sagmor commented Oct 4, 2010

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?
    twitter_token.blank?
end

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.

@josevalim
Plataformatec member

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

@sagmor
sagmor commented Oct 4, 2010

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

@sagmor
sagmor commented Oct 4, 2010

I forgot the documentation thou :P

@sagmor
sagmor commented Oct 4, 2010

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.
@josevalim
Plataformatec member

Sorry, my bad, merged!

@ledowong ledowong referenced this pull request Nov 23, 2012
Closed

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
Something went wrong with that request. Please try again.