You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Read on to see how to only fire the hooked method if certain conditions about the model's current and previous state are met.
@@ -43,56 +43,66 @@ Read on to see how to only fire the hooked method if certain conditions about th
43
43
Maybe you only want the hooked method to run under certain circumstances related to the state of your model. If a model's `status` field change from `"active"` to `"banned"`, you may want to send an email to the user:
The `was` and `is_now` keyword arguments allow you to compare the model's state from when it was first instantiated to the current moment. You can also pass `"*"` to indicate any value - these are the defaults, meaning that by default the hooked method will fire. The `when` keyword specifies which field to check against.
60
+
The `WhenFieldValueWas` and `WhenFieldValueIs` conditions allow you to compare the model's state from when it was first instantiated to the current moment. You can also pass `"*"` to indicate any value - these are the defaults, meaning that by default the hooked method will fire.
55
61
56
62
## Preventing state transitions
57
63
58
64
You can also enforce certain disallowed transitions. For example, maybe you don't want your staff to be able to delete an active trial because they should expire instead:
If you need to hook into events with more complex conditions, you can take advantage of `has_changed` and `initial_value`[utility methods](advanced.md):
147
+
If you need to hook into events with more complex conditions, you can [write your own conditions](advanced.md), or take advantage of `has_changed` and `initial_value`[utility methods](advanced.md):
0 commit comments