Re: [Rails-core] Validate absence of

2012-02-27 Thread Xavier Noria
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?

[Rails-core] Re: Validate absence of

2012-02-27 Thread Paul Gillard
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

Re: [Rails-core] Re: Validate absence of

2012-02-27 Thread Nicolás Sanguinetti
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

Re: [Rails-core] Re: Validate absence of

2012-02-27 Thread Peter Vandenabeele
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.

Re: [Rails-core] Validate absence of

2012-02-27 Thread Everton Moreth
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