-1

One interaction in my application will require that users claim one of three available meeting times. When a meeting time is claimed, I want it to disappear from view for any user who comes along later to avoid double booking. How best to do this just in terms of structuring the data?

Here is my current thinking:

I have three datetime columns: call_option_1, call_option_2, and call_option_3

I've created three additional integer columns: call_option_1_status, call_option_2_status, and call_option_3 status.

I essentially only need two statuses - unclaimed and claimed.

Should I create a model called CallOptionStatus and seed it with those two status names?

What is the best way to handle simple statuses like this in rails?

Thanks! Michael

mike9182
  • 269
  • 1
  • 3
  • 17

1 Answers1

0

In these situations, where you have data that changes state, there is a good chance you will want to use a Rails enum.  Example:

#model: UserCallOption
  user_id:integer, state:integer, date:datetime


#define enum
class UserCallOption < ActiveRecord::Base
  enum status: [:claimed, :unclaimed]
end


option.status # => unclaimed
option.claimed! # status changed to `claimed`
option.status # => claimed

This article might help you: How do i specify and validate an enum in rails?

kansiho
  • 532
  • 4
  • 18