Last active
May 4, 2017 10:04
-
-
Save gudata/4eb9ad5890cf04b3551f0fa3358b8327 to your computer and use it in GitHub Desktop.
state tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state_machine :state, initial: :init do | |
before_transition any => any do |transition| | |
@status_before_transition = transition.state_name | |
end | |
after_transition any => any do |transition| | |
log = "#{@status_before_transition} -> #{transition.state_name}" | |
SystemEvent.create(trackable: transition, description: log, tag: "state_change") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE system_events ( | |
id integer NOT NULL, | |
tag character varying NOT NULL, | |
description text, | |
trackable_id integer, | |
trackable_type character varying, | |
created_at timestamp without time zone NOT NULL, | |
updated_at timestamp without time zone NOT NULL | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add in manage event tracking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SystemEvent < ApplicationRecord | |
belongs_to :trackable, optional: true, polymorphic: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment