Created
March 21, 2015 15:09
-
-
Save karlosmid/7aa58a39d6766ed41be2 to your computer and use it in GitHub Desktop.
Check for PG::UniqueViolation exception
This file contains hidden or 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
| def create | |
| @provider = Provider.new(provider_params) | |
| begin | |
| if @provider.save | |
| redirect_to @provider | |
| else | |
| render 'new' | |
| end | |
| rescue Exception => what | |
| if what.message.include? "PG::UniqueViolation" | |
| @provider.errors.add :name, "name and url pair must be unique!" | |
| else | |
| @provider.errors.add :name, what.message | |
| end | |
| render 'new' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment