> Hello everyone, in my model I have amongst other fields, the :variant_id
and :cart_id, I want to validate their presences but in my app the user only
needs to set one of them, so I can''t make it validates_presence_of
:variant_id, :cart_id.
>
> I am sure there''s a solution for that, please tell me if you know!
You can either write a custom validation method that returns false if both are
unset or you could add some :if => {...} code to your validation line so it
only validates one field if the other is blank. You''d need that on
both validation lines and your error message would be a little confusing
suggesting the user needs to pick both.
If it was me, I''d go custom so I could put up a reasonable error
message.
--
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.