Is there a way of using the 'validates*' methods inside another
method? For instance, I need to make sure a field is empty under a
certain set of circumstances and contain data under a different set of
circumstances. I would like to keep all the logic in one place and
have the benefits of what Rails has to offer for validations,
something like this (simplified):
validate :check_amount
def check_amount
if my_condition_is_true
self.errors.add :amount, 'should be empty.'
else
validates_numericality_of :amount # this does not work
end
end
Thanks in advance
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment