Use find_or_create_by to avoid duplicate records (#5092)
This commit is contained in:
parent
ac4e7eca90
commit
dc5ec4e52f
1 changed files with 1 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ class PollSkipsController < ApplicationController
|
|||
before_action :authenticate_user!, only: %i[create]
|
||||
|
||||
def create
|
||||
@poll_skip = PollSkip.create(poll_id: poll_skips_params[:poll_id], user_id: current_user.id)
|
||||
@poll_skip = PollSkip.find_or_create_by(poll_id: poll_skips_params[:poll_id], user_id: current_user.id)
|
||||
@poll = Poll.find(poll_skips_params[:poll_id])
|
||||
render json: { voting_data: @poll.voting_data,
|
||||
poll_id: poll_skips_params[:poll_id].to_i,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue