rsvp.theoandpat.com had boolean flag to marked whether or not a visitor was going to be able to make it to our wedding. Unfortunately, if you selected you were not able to make it and submit the form, the application would return saying it could not process your submission because you have to say that you are going to make it. I argued, this is an RSVP form so you have to accept if you are RSVPing. That’s the point of the RSVP! Only people RSVP would bother submitting the form! Pat wasn’t too happy about that and ask/told me to fix it.Â
Digging into it, it turns out the way for validates_presence_of
relies on Object#blank
which of course when sent
false.blank? # returns true
Reading up on the documentation, it is suggested to use validates_inclusion_of
when dealing with booleans.
The one line change solved the problem:
validates_inclusion_of :accepted, :in => [true, false]
Thanks for that ! I was wondering why that kept throwing a validation warning. definitely not the behaviour you’d expect from validate_presence_of
Thank you. I’ve been fighting the error for a couple of hours, now found your solution, works like a charm.
I think it makes perfect sense. Don’t use validate_presence_of unless you know what .present? returns for your expected values.