[Rails] Custom Validations

Jonathan Viney
Sun, 02 Apr 2006 02:11:01 -0000

You could do something like:

validates_presence_of :a, :if => Proc.new { |r| !r.b? }
validates_presence_of :b, :if => Proc.new { |r| !r.a? }

-Jonny.

On 4/2/06, Robert MannI <robmnl@gmail.com> wrote:
>
> Does anyone how to create a validation that:
>
> validates_presence_of :a  OR :b
>
>
> I.e. :a OR :b must be present.
>
> I thought this would probably be possible with some kind of validation
> callback, e.g.:
>
> def check_a_or_b_is_set
>   return (a or b)
> end
>
>
>
> Any ideas?
>
>
> Thanks,
> Rob
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...