Requiring one field or another

I’m fairly new to Rails so I’m having some trouble with what is probably
an easy task. Any assistance would be appreciated.

I have two fields, I only have to have one of them filled in…

At the moment I’m working on some variation of

validates_presence_of :foo, :if => “bar.empty?”

Verbatim, that will of course not work…

Suggestions?

On 16-Mar-07, at 4:14 PM, Tom von S. wrote:

Verbatim, that will of course not work…

Suggestions?

Tom, :if takes a ‘block’

validates_presence_of :foo, :if => Proc.new { | your_model_instance
| your_model_instance.bar.empty? }

as you can see, the block is passed the current instance, which you
can examine - returning tru means the validation will take place.

cheers,
Jodi

Jodi S. wrote:

Tom, :if takes a ‘block’

validates_presence_of :foo, :if => Proc.new { | your_model_instance
| your_model_instance.bar.empty? }

as you can see, the block is passed the current instance, which you
can examine - returning tru means the validation will take place.

Ah, much like the example in the docs (which I somehow didn’t “get”).

Thank you,
Tom