Erwin
2012-Feb-16 14:46 UTC
rails validation presence of all attributes in a group or none
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 ... thanks fyfb -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2012-Feb-16 14:55 UTC
Re: rails validation presence of all attributes in a group or none
On 16 February 2012 14:46, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.