Last active
December 23, 2015 20:45
-
-
Save skwp/b05009ca915e32d2d1ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyThing < ActiveRecord::Base | |
private | |
def create_or_update | |
super | |
rescue ActiveRecord::RecordNotUnique => e | |
case e.message | |
when /index_mytable_on_sku_unique/ | |
errors.add(:sku, :taken) | |
else | |
# This should not happen; we want to know if we forgot to handle some unique constraint | |
raise e | |
end | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment