dhmspector
2009-Mar-26 18:26 UTC
Help with a validation issue..? Tying 2 validations together
Hi,
I am trying to validate a field upon the presence of a value of
another field -- the two are linked
for example my records have fields like this:
t.decimal "admin_headcount", :precision =>
10, :scale => 2, :default => 0.0
t.decimal "admin_comp", :precision
=>
10, :scale => 2, :default => 0.0
My forms have fields for entering of both values, however, the form
should post an error if the user tries to submit the form if there is
a non-zero value for headcount but the compensation amount is zero,
and vice versa.
Is there a way to tie
validates_numericality_of :admin_comp
validates_numericality_of :admin_headcount
to each other..?
In essence: validates_numericality_of :admin_comp,
unless :admin_headcount <= 0
any simple and obvious way to accomplish this..?
regards,
DHMS
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Greg Donald
2009-Mar-26 18:51 UTC
Re: Help with a validation issue..? Tying 2 validations together
On Thu, Mar 26, 2009 at 1:26 PM, dhmspector <dhmspector-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In essence: validates_numericality_of :admin_comp, > unless :admin_headcount <= 0 > > > any simple and obvious way to accomplish this..?validates_numericality_of :admin_comp, :unless => Proc.new{ |r| r.admin_headcount <= 0 } -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---