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
In order to run validations specific to certain events I've been using the following pattern:
aasm :state do
state :state1
state :state2
state :state3
event :myevent1 do
before do
class_eval do
validate :some_custom_validation
end
end
transitions from: :state1, to: :state2
end
event :myevent2 do
before do
class_eval do
validate :some_custom_validation
end
end
transitions from: :state2, to: :state3
end
end
This works just fine but it has always felt a little clunky.
It would be really nice if one could configure your events to fire with a context equal to the event name - and/or to override the context passed to save.
This will allow one to end up with something like:
validate :some_custom_validation, on: [ :myevent1, :myevent2 ]
aasm :state, event_as_context: true do
state :state1
state :state2
state :state3
event :myevent1 do
transitions from: :state1, to: :state2
end
event :myevent2 do
transitions from: :state2, to: :state3
end
end
Is this something that would be a useful contribution or am I barking up the wrong tree and should be handling things differently?
The text was updated successfully, but these errors were encountered:
In order to run validations specific to certain events I've been using the following pattern:
This works just fine but it has always felt a little clunky.
I've recently come across a blog post discussing validation contexts and it immediately made me think of
aasm
.It would be really nice if one could configure your events to fire with a context equal to the event name - and/or to override the context passed to save.
This will allow one to end up with something like:
Is this something that would be a useful contribution or am I barking up the wrong tree and should be handling things differently?
The text was updated successfully, but these errors were encountered: