calling custom validation methods in Rails

Your validations are executed when you use the validate method. However rails doesn’t relies on the returned value.

It relies on if there are validations errors or not. So you should add errors when your model doesn’t validates.

def something
    errors.add(:field, 'error message')
end

Or, if the error is not related to a field :

def something
    errors.add(:base, 'error message')
end

Then your model won’t be saved because there are errors.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)