# Validates\_presence\_of :if

**URL:** <https://www.ruby-forum.com/t/validates-presence-of-if/137681>\
**Category:** Rails\
**Created:** [May 15, 2008, 9:24am UTC](https://www.ruby-forum.com/t/validates-presence-of-if/137681 "2008-05-15T09:24:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 15, 2008, 9:24am UTC](https://www.ruby-forum.com/t/validates-presence-of-if/137681/1 "2008-05-15T09:24:02Z")

</div>

Hi  
I have a table service\_desk\_resolution\_codes as below  
id | name  
----±-----------------  
1 | \<\< Select Any \>\>  
2 | Resolution 1  
3 | Resolution 2

And I am using this to submit resolution code in select box in a  
view.What i need is if the user select \<\< Select Any \>\> a validation  
check is done says that this is not acceptable select any resolution  
code…(Currently i have implemented it with a javascript).But how can i  
do it in the model ServiceDeskResolution…Is the following way correct  
validates\_presence\_of :service\_desk\_resolution\_code\_id, :if  
=\>“service\_desk\_resolution\_code\_id==1”

Surely this is error…But how can I do it in correct way

service\_desk\_resolution\_code\_id is a field of the table  
service\_desk\_resolutions  
Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 15, 2008, 5:17pm UTC](https://www.ruby-forum.com/t/validates-presence-of-if/137681/2 "2008-05-15T17:17:32Z")

</div>

Rather than putting your prompt text in the table, get rid of it, and  
when you need to provide a drop-down for resolution code use the :prompt  
argument to have rails insert the prompt for you. I believe that will  
allow you to just put a “validates\_presence\_of :resolution\_code” in the  
appropriate model & rails will “know” not to accept the prompt value.

So your call to collection\_select might look like:

\<%= f.collection\_select(:resolution\_code,  
ResolutionCode.find(:all),  
:id,  
:name,  
{:prompt =\> ‘Please select a resolution’}  
) %\>

HTH,

-Roy
