On 16 February 2012 14:46, Erwin <[email protected]> wrote:
> I am trying to validate the presence of banking data of a customer
> ( bank name, bank address, bank branch, ...)
>
> If one of these fields is not blank then all other fields should be
> filled...
> Is there a smart way to validate it .. i.e validate presence of a
> group of attributes ...
# in your model
validate :all_or_none_address_fields
def child_and_team_code_exists
address_fields = [address1, address2, address3, town, county,
postcode] # these are all the attributes of the model you want all or
none of
errors.add_to_base("All of the address fields need a value if any
of them are entered") if
address_fields.any? && !address_fields.all?
end
--
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 [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-talk?hl=en.