StateMachine for my project

Help me understand StateMachine for my project and where it fits in. As soon as the user registers I need to show him 4 challenges he can pick from which last for 7 days. After 7 days I show him 2 challenges of 30 days he can choose from. After he chooses one of the challenges I want to not show him the option of choosing a challenge.

Where does the StateMachine concept fit here?

You could have different states for User model like:

state :registered, initial: true
state :started_basic
state :completed_basic
state :started_advanced
state :completed_advanced
state :finished

So when a user registers he’s in registered state. When he decides on one of the first 4 challenges he is in started_basic. Upon completion you move him to completed_basic and when he decides on the next challenge you move him to started_advanced

Keep in mind the things that @Daryl mentioned in the other post. This approach also has its downsides - what doesn’t? :slight_smile:

Something like this?

 state_machine initial: :registered do
    state :started_basic
    state :completed_basic
    state :started_advanced
    state :completed_advanced
    state :finished,value: 1

    event :start_basic do
      transition :registered => :started_basic
    end

    event :complete_basic do
      transition :started_basic => :completed_basic
    end

    event :start_advanced do
      transition :completed_basic => :started_advanced
    end

    event :complete_advanced do
      transition :started_advanced => :completed_advanced
    end

    event :complete_advanced do
      transition :started_advanced => :completed_advanced
    end

    event :finish do
      transition :completed_advanced => :finished
    end

end