Created
December 30, 2010 01:53
-
-
Save cherring/759350 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class KlassB | |
| def do_something | |
| save | |
| send email or some such thing | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyKlass | |
| after_save :do_something, :if => :condition_for_callback | |
| def do_something | |
| send_email or some such thing | |
| end | |
| def condition_for_callback | |
| send or not? | |
| end | |
| end |
Author
My take: do you ALWAYS always always want to send the email every time you save? Then go with the after_save hook.
Author
Ok so how about if there is a condition on it? like the gist is now?
if the condition_for_callback function is going to be used for other stuff, thats cool. or if it'll make it easier to test. if not, it seems like things are getting complex/verbose a bit early perhaps?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What are thoughts on callbacks vs just having a method that does something and includes the save inside it? Is it personal taste? Do people not care, or should it be something like have the method that does something but call save separately?