Skip to content

Instantly share code, notes, and snippets.

@skwp
Last active December 23, 2015 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skwp/b05009ca915e32d2d1ae to your computer and use it in GitHub Desktop.
Save skwp/b05009ca915e32d2d1ae to your computer and use it in GitHub Desktop.
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