On Mon, Feb 27, 2012 at 10:15 AM, Paul Gillard paulmgill...@gmail.com wrote:
I often need to validate the absence of active record fields. That
validation being the direct opposite of validating the presence of a
field. Would the core team be willing to accept a patch to that
effect?
Two that spring to mind are:
validates :auth_code, :absence = true, :unless = :payment_complete?
validates :comments, :absence = true, :unless = published?
There may in some cases be some perceived repetition along the lines
of the code below. I'd be interested to hear people's thoughts on if
On Mon, Feb 27, 2012 at 11:15 AM, Paul Gillard paulmgill...@gmail.com wrote:
Two that spring to mind are:
validates :auth_code, :absence = true, :unless = :payment_complete?
If the auth_code is something that won't be set until you get a
response from your payment gateway, then why bother with
On Mon, Feb 27, 2012 at 2:15 PM, Paul Gillard paulmgill...@gmail.comwrote:
validates :comments, :absence = true, :unless = published?
A particular problem I would expect with this one is that a post
that has already received comments while it was published cannot
easily be unpublished.
I believe that this one was a bad example...
I found myself implementing this a couple times in the last year:
validate :a_or_b
def a_or_b
if a? b?
self.errors.add :a, You can't choose both options at the same time.
end
end
One of the cases was extremely common:
Choose