How can I add errors to the User
model manually?
Is it just @user.errors << "some text goes here"
?
Join Stack Overflow to learn, share knowledge, and build your career.
How can I add errors to the User
model manually?
Is it just @user.errors << "some text goes here"
?
@user.errors.add(:email, "Not valid")
If you don't want to use any attributes, then in your model
@user.errors[:base] << "This person is invalid because ..."
For details: link
WARNING
If you just add errors in a separate method (not in a validation), then by default when you call .valid?
or .save
those errors will be automatically cleared. So you may want to use validation contexts instead.