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.

Christopher Warren 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,