after hooks need more awareness
Reported by Troy K | June 25th, 2008 @ 10:54 AM | in 1.x
Best I can tell, after hooks are left in the dark as to what has transpired. Specifically, for CRUD operations, after hooks always fire regardless of the result, and there appears no way to obtain the result. I suggest either:
1) not firing after create,update,destroy,save is the result is false.
2) having the result of create,update,destroy,save exposed through created?,updated?,destroyed?,saved?
We are currently having to bypass the aspect love and do stuff like
... dm::resource ...
def save
result = super
if result
Activity.log(self)
Searcher.update(self)
end
result
end
def destroy
result = super
if result
Activity.log(self)
Searcher.remove(self)
end
result
end
but would rather do something like:
... dm::resource ...
after :save do
# this would never get called if save == false
Activity.log(self)
Searcher.update(self)
end
or
... dm::resource ...
after :save do
return unless saved?
Activity.log(self)
Searcher.update(self)
end
The astute may recommend using transactions and before hooks, but that would require the hooks to be attached to both after create (need the id) and before update, instead of the nice clean, DRY after update.
I can submit a patch implementing your preferred approach, if any.
thanks -- troy
Comments and changes to this ticket
-
Carl Lerche July 5th, 2008 @ 02:05 PM
What if after hooks could accept the return value of the function as an argument.
after :save do |saved| throw(:halt) unless saved # Or return if you want the rest of the hooks to run ... end -
Carl Lerche July 6th, 2008 @ 12:16 PM
- → Assigned user changed from Sam Smoot to Carl Lerche
- → State changed from new to open
-
Carl Lerche July 6th, 2008 @ 12:22 PM
- → Milestone changed from to 1.x
-
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
