On Mon, Feb 27, 2012 at 2:15 PM, Paul Gillard <[email protected]>wrote:
> 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.
> post.update_attributes(:published => false)
will then fail because of this validation (and does it makes sense
to delete all comments when setting it to unpublished?).
A possible validation could then be:
validates :comments, :absence => true, :if => never_published?
More fundamentally, maybe there is a confusion between:
* "validations" as intended to validate the user enter correct values
through the {AP|GU}I before processing/persisting this data input
* "assertions" as intended to double check the internal state of
the program (I would typically raise an "internal error" with
explanation on the problem if such an assertion failed).
HTH,
Peter
--
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.