Rails getting validation failed error, but no errors in ActiveRecord error model
When you have before_validation
declarations and if they return false
then you'll get a Validation failed (ActiveRecord::RecordInvalid)
message with an empty error message (if there are no other errors).
Note that before_validation
callbacks must not return false
(nil
is okay) and this can happen by accident, e.g., if you are assigning false
to a boolean attribute in the last line inside that callback method. Explicitly write return true
in your callback methods to make this work (or just true
at the end if your callback is a block (as noted by Jesse Wolgamott in the comments)).
UPDATE: This will no longer be an issue starting Rails 5.0, as return false
will no longer halt the callback chain (throw :abort
will now halt the callback chain).
UPDATE: You might also receive ActiveRecord::RecordNotSaved: Failed to save the record
if a callback returns false
.