From 4f10b5e940e7b9bcc83279fb6a804f7457f7bd1a Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 6 Apr 2016 13:18:11 +1000 Subject: [PATCH] avoid exception for general case --- app/models/user_first.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/user_first.rb b/app/models/user_first.rb index 6a953b5d164..4f78620379c 100644 --- a/app/models/user_first.rb +++ b/app/models/user_first.rb @@ -5,6 +5,9 @@ class UserFirst < ActiveRecord::Base end def self.create_for(user_id, type, post_id=nil) + # the usual case will be that it is already in table, don't try to insert + return false if UserFirst.exists?(user_id: user_id, first_type: types[type]) + create!(user_id: user_id, first_type: types[type], post_id: post_id) true rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique