First New Year’s Eve as parent…
First New Year’s Eve as parents: dinner at 5, boy in bed at 6:30, 1 game of Risk, no alcohol, wife in bed by 8:30, husband twittering.
First New Year’s Eve as parents: dinner at 5, boy in bed at 6:30, 1 game of Risk, no alcohol, wife in bed by 8:30, husband twittering.
Snow falling. Downy woodpecker on Aspen tree. French toast and coffee consumed. "For Unto Us a Child is Born" on the radio. Christmas.
Annie’s mac ‘n cheese with tobasco sauce.
Getting this project rolled up for Ameritrade before the holiday. 123 requirements to go
Trying very hard not to run from the building in an edvard-munch-the-scream pose.
Learning RSpec. Whatever happened to the days of anchor tags and a few tables here and there?
My fourth cup of the day.
Update: December 18, 2007: less code, same result
If you use the Restful Authentication plugin with the –include-activation and –stateful options (see Acts_As_State_Machine and the post by Jonathan Linowes which united the two plugins), you’ll need to make a couple modifications to the code after you run the generator in order to keep the user activation email from being sent simultaneously with the user signup notification email.
The UserObserver code sends an activation email during the after_save callback if the user’s state is “pending.” Without activation the state transition goes from pending to active and we can leave the code alone. With activation, however, we introduce another state: the “state of being notified that our account has been created.”
If we change the UserObserver to watch for an “active” state instead of “pending,” the user will receive an activation email every time we save the user’s record and that puts the user into the state of “I’m about to adios this annoying website.”
We add a temporary state “notified” between pending and active that allows us to send the activation email at the right time with little disruption to the original restful authentication code.
Just before we “activate!” the user in the UserController, we “notify!” them, putting them in the “notified” state, save the user, which calls the after_save callback, which sends the activation email, and then return control to the UserController, which calls “activate!,” putting the user in the “active” state.
Update: I removed the :do_notify code which was redundant (state transitions automatically save the record)
state :notified event :notify do transitions :from => :pending, :to => :notified end event :activate do transitions :from => :notified, :to => :active end event :suspend do transitions :from => [:passive, :pending, :notified, :active], :to => :suspended end event :delete do transitions :from => [:passive, :pending, :notified, :active, :suspended], :to => :deleted end
def after_save(user) UserMailer.deliver_activation(user) if user.notified? end
# In the activate method, # insert the notify! line right before the activate! line current_user.notify! current_user.activate!
If I’ve left something out, or if you have a better solution, please say so below. Cheers!
Remembering my Dave Gardner: "James Lewis! Get away from that wheelbarrow, say you know you doesn’t know nothing about machinery!"
Drawing on a Christmas card envelope with a used Earl Grey teabag.