New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally skip email validation. #545

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@sagmor
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Oct 4, 2010

Member

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

Member

josevalim commented Oct 4, 2010

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

@sagmor

This comment has been minimized.

Show comment
Hide comment
@sagmor

sagmor Oct 4, 2010

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@sagmor

sagmor Oct 4, 2010

Contributor

I forgot the documentation thou :P

Contributor

sagmor commented Oct 4, 2010

I forgot the documentation thou :P

@sagmor

This comment has been minimized.

Show comment
Hide comment
@sagmor

sagmor Oct 4, 2010

Contributor

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.
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Oct 4, 2010

Member

Sorry, my bad, merged!

Member

josevalim commented Oct 4, 2010

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