Class: OrderObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
app/models/order_observer.rb

Instance Method Summary collapse

Instance Method Details

#after_transition(record, attribute_name, event_name, from_state, to_state) ⇒ Object

Generic transition callback after the transition is performed



5
6
7
8
9
10
11
12
13
14
# File 'app/models/order_observer.rb', line 5

def after_transition(record, attribute_name, event_name, from_state, to_state)
  current_user_session = UserSession.activated? ? UserSession.find : nil
  author = current_user_session ? current_user_session.user : record.user
  record.state_events.create({
      :previous_state => from_state,
      :name           => event_name,
      :user_id        => author && author.id 
    })
  ActiveRecord::Base.logger.info("Order##{record.id}: #{from_state} => #{to_state}")
end