🖥

#Rails - In controller Block double request / duplicated proceeding wi

2019/12/23に公開
class SomeController
  def create
    ProceedingHistory.transaction do
      begin
        ProceedingHistory.create(proceeding_id: proceeding_id)
      rescue ActiveRecord::RecordNotUnique
        head :bad_request
        return
      end

      do_something
    end

    head :ok
  end
end

# == Schema Information
#
# Table name: proceeding_histories
#
#  id              :bigint           not null, primary key
#  created_at      :datetime
#  proceeding_history_id :string(255)
#
# Indexes
#
#  index_proceeding_histories_on_proceeding_history_id  (proceeding_history_id) UNIQUE
#

class ProceedingHistory < ApplicationRecord
end

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/2863

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-12-23

Discussion