validates_presence_of , unless.....

I've got a case for my model where the name field is required, ONLY if
the comment field has been filled out. I thought I could do this like

validates_presence_of :name, :unless=>@comment.nil?

but I can't seem to get the syntax right, can somebody help me out? I'm
not sure how the incoming data has been provided to the model, so that I
can reference the value of what is going to be the comment field, if
that makes sense.

If you want to put the condition inline, you have to do something like

validates_presence_of :name, :unless => { |comment| comment.nil? })

Alternatively, you can specify a method to call.

validates_presence_of :name, :unless => :comment_absent?

def comment_absent?

Here are the docs: