docbrown/app/controllers/poll_skips_controller.rb
rhymes 582d32393c
Small ActiveRecord optimizations: begone race conditions and hello bulk insert (#8436)
* Replace PollSkips find_or_create_by with create_or_find_by

* Use insert_all to add users to a channel in bulk

* Use bulk insert for DataUpdateScript and set private what shall be private

* oops
2020-06-15 17:57:14 +02:00

22 lines
506 B
Ruby

class PollSkipsController < ApplicationController
before_action :authenticate_user!, only: %i[create]
def create
poll = Poll.find(poll_skips_params[:poll_id])
poll.poll_skips.create_or_find_by(user_id: current_user.id)
render json: {
voting_data: poll.voting_data,
poll_id: poll.id,
user_vote_poll_option_id: nil,
voted: false
}
end
private
def poll_skips_params
accessible = %i[poll_id]
params.require(:poll_skip).permit(accessible)
end
end