-
Notifications
You must be signed in to change notification settings - Fork 645
Open
Description
aasm column: :status, whiny_transitions: false do
state :requested, initial: true
state :approved
event :approve, after: :after_approve do
transitions from: :requested, to: :approved
end
end
def after_approve
raise "This is a test"
end
Given the above I want to be able to call obj.approve!
and still have it return true
or false
so I can handle the exceptions in the model, add errors to the object and handle it in the controller.
I have tried returning false, error handlers etc but it seems there is no way to stop the event from the after callback without raising, nor is there any way to catch the exception handle it and return false (that I can find).
As a workaround I've had to create a new method which wraps the call to approve!
def approve_with_errors
approve!
rescue StandardError => e
errors.add(:base, "Error: #{e}")
false
end
Is there no way to achieve this in aasm without adding these wrappers?
Metadata
Metadata
Assignees
Labels
No labels