-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging transitions with DRY code? #221
Comments
@awendt There's already a ticket for something similar (take a look at #108). Would that help you? What you could do now already is to use methods instead of a aasm do
transitions from: :initialized,
to: :mismatched,
after: :tracking
end
def tracking(*args)
track(
'from_state' => aasm.from_state,
'into_state' => aasm.to_state,
'statemachine_event' => aasm.current_event
)
end |
@alto Thanks for your quick reply. Anything that involves me declaring "I want this code to run after every transition" just once helps here :) I found #108 but failed to see a connection. After more careful reading I found this comment:
So, yes, that exactly describes the issue I'm having. I think I will switch to symbols and add |
@awendt How exactly are you using alias_method_chain with this? I'm running into the same problem, are you including it in the |
@waynn I settled for a duplicated |
Please take a look at #270 and let me know if that works for your problem. Will release soon. |
That looks good! |
👍 — should I close this then? |
Closed with #270 . |
I just released version |
With a fairly complex state machine, we'd like to log transitions so we know how we ended up in the current user state. For each transition, we'll need:
aasm.from_state
aasm.to_state
aasm.current_event
According to the docs:
This means we'll go from this:
to this:
for each transition which is undesirable from a maintenance perspective. I'm aware of things like
paper_trail
for auditing AR but that does not fit into our current architecture.So I'm wondering if there's a way to get this done while staying DRY? (I'm leaning toward
alias_method_chain
to add the callback—but there may be another, AASM-supported way I'm not aware of.)The text was updated successfully, but these errors were encountered: