Skip to content

Commit

Permalink
fix: fixed ActiveRecord::RecordNotUnique (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
urumo authored May 7, 2021
1 parent 14d3969 commit 58bf8b2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def self.check_caller_status(caller_id, message_id, chat_id)
caller.admin
end

def self.get_user(target, chat_id) = User.find_or_create_by(tg_id: target.id, user_name: target.username,
chat_id: chat_id)
def self.get_user(target, chat_id)
User.find_or_create_by(tg_id: target.id, user_name: target.username, chat_id: chat_id)
rescue ActiveRecord::RecordNotUnique
User.find_by(tg_id: target.id, user_name: target.username, chat_id: chat_id)
end
end

0 comments on commit 58bf8b2

Please sign in to comment.