Skip to content
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

validates :url => true also validates for presence #47

Closed
keilmillerjr opened this issue Oct 14, 2012 · 6 comments
Closed

validates :url => true also validates for presence #47

keilmillerjr opened this issue Oct 14, 2012 · 6 comments

Comments

@keilmillerjr
Copy link

An error should not be thrown if the field is blank. This should be handled with :presence validator.

@franckverrot
Copy link
Owner

Thanks for reporting this @keilmillerjr.

Do you want to send a PR ?

Thanks again!

@franckverrot
Copy link
Owner

I've been investigating a bit the other validators' behaviors and it seems they all behave the same and will throw an error if the field is blank. Have you tried something like validates :url, url: true, unless: :blank?

If this still doesn't work, I'll reopen the issue.

Thanks a lot!

@rahult
Copy link

rahult commented Dec 4, 2012

I am getting the same error.

Tried using unless: blank? but no luck.

@LaurentSHB
Copy link

FYI it doesn't work with unless: blank? but it works fine with allow_blank: true

So you can write:

validates :link_url, url: true, allow_blank: true

It works for me with Rails 4.0

@theSociableme
Copy link

A note or example of this on the readme would be helpful.

franckverrot added a commit that referenced this issue Oct 17, 2014
@franckverrot
Copy link
Owner

Done. Thanks !

danielrorspace added a commit to danielrorspace/activevalidators that referenced this issue Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants