Rails: model.save returns false, but models.errors is an empty hash
This means that one of your callbacks will probably stop saving, but does not contain a validation error.
Check return values, in particular any callbacks, before_
and make sure they don't returnfalse
If they return false
, then the active entry will stop future callbacks and return false from save.
You can read a bit about it here under "Canceling Callbacks"
source to share
1) Disable before_create, before_save, before_update and check where it saves the day
2) If rollback is caused by one of these methods, make sure that these methods return true if you do not plan to rollback.
For example, if you set the default for a boolean field to avoid nil, you would probably do it like this.
def set_defaults_before_create
self.my_boolean_field ||= false
end
In this example, the set_defaults_before_create method always returns false and thus rolls back the transaction. So refactor it to return true
def set_defaults_before_create
self.my_boolean_field ||= false
true
end
source to share