I would like to do the following from a library class?
class LibClass
def create_user(provider)
user = User.new
if provider == "facebook"
user.validates_presence_of :email
else
# dont validate presence of email
end
end
end
I am aware that I can do a self.validates_presence_of :email inside the User class, but I am in the library class and am not sure how to do this?
In your
Usermodel, you can create an accessor to toggle the validation on or off.You can turn the validation on by setting
user.validate_email = true:To actually get the validations to run, you can call
user.valid?and the hashuser.errorswill be populated with any validation errors.