# Weirdness with validates\_presence\_of

**URL:** <https://www.ruby-forum.com/t/weirdness-with-validates-presence-of/61264>\
**Category:** Rails\
**Created:** [May 22, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/weirdness-with-validates-presence-of/61264 "2006-05-22T16:07:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [May 22, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/weirdness-with-validates-presence-of/61264/1 "2006-05-22T16:07:02Z")

</div>

Hi,

I have a call to validates\_presence\_of in my model and it is behaving  
very  
strangely

my first stab when this happened during testing was

validates\_presence\_of :impact, :ease\_to\_implement if Proc.new { |record|  
!record.cost\_estimate.nil? }

I have three values in my model that I care about with this one.  
Basically  
what I’m trying to get to happen is  
if one is there they all must be there. (there are a couple more of  
these  
validates\_presence\_of with the orders swapped around)

but this executes the validation every time regardless of if there is  
any of  
these set.

> From here I tried some other things… The most basic that I tried was

validates\_presence\_of :impact if Proc.new{ false }  
and also  
validates\_presence\_of :impact if Proc.new{ true }

and the validation still happened in my test. (also in the console)

What is going on??

PS  
Windoze XP  
ruby 1.8.4  
rails 1.1.2

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [May 22, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/weirdness-with-validates-presence-of/61264/2 "2006-05-22T16:35:01Z")

</div>

Sorry to post a reply to my own post.

A bit simple really.

the if should be an argument to the method ie. v\_p\_o :impact, :if =\>  
Proc.new{ some thing } instead of v\_p\_o :impact if …

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [May 22, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/weirdness-with-validates-presence-of/61264/3 "2006-05-22T17:43:45Z")

</div>

Hi Daniel,

Daniel N wrote:

> Sorry to post a reply to my own post.

No need to apologize for what is, in fact, the preferred behavior. If  
everyone did this it would be a lot easier for folks to use the archives  
to  
find answers to their problems which, in turn, would increase bandwidth  
on  
the list to address new problems. Good on you, bud.

Best regards,  
Bill
