Implementation of state machine for Rails