Seems Complex----validation

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

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.
<[email protected]

wrote:

Posted via http://www.ruby-forum.com/.


Christopher W.
[email protected]
612.424.9880

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
[email protected]