Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module SaveWithErrors
def self.prepended(base)
base.serialize :record_errors, Hash
base.after_validation :assign_errors
end
def save(*args)
super(*args) || save_anyway
end
def save!(*args)
super(*args)
rescue ActiveRecord::RecordInvalid
save_anyway
raise
end
private
def assign_errors
self.record_errors = errors.messages
end
def save_anyway
save(validate: false)
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment