app/models/concerns/state_transition_support.rb
# Transition record to given state, creating a new StateTransition record
Transition record to given state, creating a new StateTransition record
Transition record to given state creating a new StateTransition record
def transition_to(to_state, metadata={})
      if last_transition
        last_transition.update_attributes(current: false)
      end
      from_state = last_transition ? last_transition.to_state : nil
      if metadata && metadata[:request]
        metadata.delete(:request)
      end
      attributes = {
        record_id: id,
        record_type: self.class.to_s,
        from_state: from_state,
        to_state: to_state.to_s,
        user_id: metadata[:user_id],
        location_id: metadata[:location_id],
        order_id: metadata[:order_id],
        metadata: metadata,
        current: true
      }
      StateTransition.create!(attributes)
    end
def transition_to ( to_state , metadata = { } ) if last_transition last_transition . update_attributes ( current : false ) end from_state = last_transition ? last_transition . to_state : nil if metadata && metadata [ :request ] metadata . delete ( :request ) end attributes = { record_id : id , record_type : self . class . to_s , from_state : from_state , to_state : to_state . to_s , user_id : metadata [ :user_id ] , location_id : metadata [ :location_id ] , order_id : metadata [ :order_id ] , metadata : metadata , current : true } StateTransition . create! ( attributes ) end
Transition record to given state, creating a new StateTransition record
Transition record to given state creating a new StateTransition record
# remove request if included in metadata
to_state
<not_specific>
metadata
<not_specific>