lifecycle and order of execution

7 views
Skip to first unread message

tuan jim

unread,
Apr 22, 2009, 7:12:03 PM4/22/09
to Hobo Users
there have been several-to-many threads about the vagaries of the
lifecycle, but none with quite this upshot; and since i find myself
unable to deduce the solution otherwise, here we go:

using 0.8.5: the standard "verify this email address" user lifecycle
in user.rb :create has this code:

create :signup, :available_to => "Guest",
:params =>
[:username, :email_address, :password, :password_confirmation],
:become => :inactive, :if => proc {|r|
r.acting_user.guest?}, :new_key => true do
UserMailer.deliver_activation(self, lifecycle.key)
end

over in users_controller.rb i can get do_signup to do all sorts of
things, including conditional redirection, pre-population and
rendering of subsidiary models--think "sign-up wizard"--and so on.

i can *not* get the create :signup block above to deliver unto me a
valid User via self, to pass off to the deliver_activation method.
the lifecycle documentation refers to the block in create :signup as a
"callback;" however, it's easy to demonstrate with a couple of "puts"
that it runs *first*, before a user has been created. so self ==
Guest, not User.

the code in the block runs first, calls deliver_activation in
UserMailer, hits activation.erb and lays an egg: "can't convert nil
to string," when attempting to access @user (which was set up in
deliver_activation, via the "user" argument from the call
UserMailer.deliver_activation(self, lifecycle.key). the code in the
controller wraps up by creating the user.

what have i misunderstood? i'm sure it's simple, but i'm not seeing
it. thanks, y'all.

MartOn

unread,
Apr 23, 2009, 2:21:01 AM4/23/09
to Hobo Users
Not sure what your problem actually is, but I have a fully working
signup.
The only difference I can see from your code and mine are your :if
statement:
I do not have it.

Mine looks like this:
create :signup, :available_to => "Guest",
:params =>
[:name, :email_address, :password, :password_confirmation],
:new_key => true, :become => :inactive do
UserMailer.deliver_account_activation(self,
lifecycle.key)
end

Donno if it helps, but this code works for me atleast.

/MartOn

Tom Locke

unread,
Apr 23, 2009, 5:05:41 AM4/23/09
to hobo...@googlegroups.com
> i can *not* get the create :signup block above to deliver unto me a
> valid User via self

If the block has a single argument, the created user will be passed in
that argument IIRC.

Tom

tuan jim

unread,
Apr 23, 2009, 2:18:57 PM4/23/09
to Hobo Users
@MartOn: thank you for your answer. that block, i believe, is
redundant, since the precondition has (or should have been) set
by :available_to => "Guest". At any rate, I did you the disservice of
neglecting to mention that I tried it with and without, and tried a
few other variants besides.

@Tom: thank you, too. Turns out that your doc is correct, the block
requires no argument, but it did set me thinking:

The answer, it seems, was to disambiguate the process by trying it in
a new shell app, in which I had not tinkered with do_signup in the
controller or modified the model. The changes I made there--which
changes I don't know--broke do_activation.

Works like a charm.

Allow me to join the chorus of people who've pointed out that your
lifecycle work is very strong.

Eric
Reply all
Reply to author
Forward
0 new messages