On Mon, Feb 27, 2012 at 11:15 AM, Paul Gillard <[email protected]> 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 this? If what you want is to prevent users from updating this field when submitting the payment form, use attr_protected. > validates :comments, :absence => true, :unless => published? I'm guessing something that isn't published usually won't be surfaced to users, so no one will be able to comment on it. So why validate something? Adding a validation means adding code that runs each time you save your object, so validations that are just there to look nice but don't really help (because they will always be valid since there's no way the user can break them) will only make your app slower for no real benefit. I'm not saying there's no use case for this (I just can't think of any), but these particular use cases don't warrant adding anything into core, IMO. Cheers, -foca > 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 > this is acceptable. Though there is repetition I'd feel the intention > of the code is clear. > validates :auth_code, :presence => true, :if => :payment_complete? > validates :auth_code, :absence => true, :unless > => :payment_complete? > > On Feb 27, 9:18 am, Xavier Noria <[email protected]> wrote: >> On Mon, Feb 27, 2012 at 10:15 AM, Paul Gillard <[email protected]> >> 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? >> >> Interesting! Can you explain some uses cases? >> >> If it makes sense I think it could be added. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
