Skip to content

Instantly share code, notes, and snippets.

@Melrt
Created June 7, 2023 06:49
Show Gist options
  • Save Melrt/3550653e370d468d4fcc8a0a88189191 to your computer and use it in GitHub Desktop.
Save Melrt/3550653e370d468d4fcc8a0a88189191 to your computer and use it in GitHub Desktop.
# app/controllers/events/registrations_controller.rb
class Events::RegistrationsController < ApplicationController
def create
@event = Event.subscribing.find(params[:event_id])
@event.with_lock do
sleep 0.25 # simule un travail plus complexe
@ticket = Ticket.create!(
validated_at: Time.zone.now,
user_name: tickets_params[:user_name],
)
render json: @ticket, status: :created
end
end
private
def tickets_params
params.require(:ticket).permit(:user_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment