Skip to content

Instantly share code, notes, and snippets.

@cainlevy
Created July 21, 2017 01:13
Show Gist options
  • Select an option

  • Save cainlevy/574041ce4517737ca50aa554a4d1f4f0 to your computer and use it in GitHub Desktop.

Select an option

Save cainlevy/574041ce4517737ca50aa554a4d1f4f0 to your computer and use it in GitHub Desktop.

Revisions

  1. cainlevy renamed this gist Jul 21, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. cainlevy created this gist Jul 21, 2017.
    8 changes: 8 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # forgiveness is faster than permission
    private def catch_uniqueness_errors
    yield
    rescue ActiveRecord::RecordNotUnique => e
    field = e.cause.message.match(/index_([a-z_]*)_on_([a-z_]*)/)[2]
    raise unless field
    errors.add(field, :taken)
    end