Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:46:16+00:00 2026-06-12T19:46:16+00:00

I have an app where people sign up for items. Each item has a

  • 0

I have an app where people sign up for items. Each item has a limited number of slots. How can I handle concurrency? I’ve tried like this in the Item class:

def sign_up(signup)
  ActiveRecord::Base.transaction do
    return 'Sorry, that item is full.' if full?
    signups << signup
    sheet.save!
    nil
  end
end

def full?   
  locked_signups = signups.lock(true).all  
  locked_signups.size >= max_signups
end

Is what I am trying to do even possible through AR? Do I need to implement my own locking via a column? Any suggestions are welcome.

UPDATE: I got this working per tadman’s answer. Here’s the code that works:

rows_updated = ActiveRecord::Base.transaction do
   Item.connection.update "update items set signup_count=signup_count+1 where id=#{ActiveRecord::Base.sanitize(self.id)} and signup_count<quantity"
end
return 'Sorry, that item is full. Refresh the page to see what\'s still open.' if rows_updated < 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:46:18+00:00Added an answer on June 12, 2026 at 7:46 pm

    I can think of two approaches to this sort of problem that are reliable.

    Counter Column

    You’ll create a “remaining stock” column and update it atomically:

    UPDATE sheet SET signups_remaining=signups_remaining-:count WHERE id=:id AND signups_remaining>=:count
    

    You’ll have to bind to the :count and :id values accordingly. If this query runs, it means there was a sufficient number of signups left.

    Reserved Signups

    Create the signup records in advance and allocate them:

    UPDATE signups SET allocation_id=:allocation_id WHERE allocation_id IS NULL LIMIT :count
    

    This will update zero or more signup records, so you’ll have to check that you reserved the correct count before committing your transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web app where people can create custom content on the web
I have a web app where users can sign up, via Devise, and post
I have an app that lets people create tickets, and each Account owner using
I am creating a community app where people can have a profile and search
I'm a developer for a media website that has a facebook app People can
I have a basic CRUD web app where people can create articles/edit them. I
I have an app in dev that involves a small list of people, a
I have a app to manage book orders from some people, here is the
Hello people I have made a custom title bar for my app. I would
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.