# Seems Complex----validation

**URL:** <https://www.ruby-forum.com/t/seems-complex-validation/170956>\
**Category:** Rails\
**Created:** [June 24, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/seems-complex-validation/170956 "2009-06-24T12:55:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 24, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/seems-complex-validation/170956/1 "2009-06-24T12:55:46Z")

</div>

Hi everyone,  
i have 20 fields in users table.  
in my admin profile module the admin can modify his infomation.  
but only 12 fields he can able to modify.  
for the users email field is not mandatory.but for admin email is a  
mandatory field.  
how can i use the validates\_presence\_of method under this requirement.  
pls help

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 24, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/seems-complex-validation/170956/2 "2009-06-24T13:16:06Z")

</div>

Make an is\_admin? method on your user.  
def is\_admin?  
self.admin # Or how ever you figure out the person is an admin  
end

In your validation:

validates\_presence\_of :email, :if =\> :is\_admin?

That should do it.

On Wed, Jun 24, 2009 at 5:55 AM, Newb N.  
\<removed\_email\_address@domain.invalid

> wrote:

> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Christopher W.  
removed\_email\_address@domain.invalid  
612.424.9880

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 24, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/seems-complex-validation/170956/3 "2009-06-24T22:38:29Z")

</div>

Christopher W. wrote:

> Make an is\_admin? method on your user.  
> def is\_admin?  
> self.admin # Or how ever you figure out the person is an admin  
> end

By Ruby convention, the usual way of naming this method would be admin?  
– and ActiveRecord already gives you that for free if you have an admin  
field.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
