On Tue, Apr 29, 2008 at 12:25 PM, Duane Morin <
rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>
> 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
> this:
>
> validates_presence_of :name, :unless=>@comment.nil?
If you want to put the condition inline, you have to do something like
validates_presence_of :name, :unless => Proc.new { |comment| comment.nil? })
Alternatively, you can specify a method to call.
validates_presence_of :name, :unless => :comment_absent?
def comment_absent?
@comment.nil?
end
Here are the docs:
http://www.railsbrain.com/api/edge/doc/index.html?a=M001604&name=validates_presence_of
Regards,
Craig
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---