Rick Lloyd wrote:
> Not sure I understand your problem...
> 
> I don't see any mention of UsersController#save anywhere in either
> restful_authentication/lib/... or in the controllers and views created
> using script/generate authenticated User Sessions --options...

The save method is the original ActiveRecord save method. It doesn't 
have to do anything with acts_as_state_machine! ;-)

Just look at the following to see what I mean:

josh$ script/console
Loading development environment (Rails 2.1.0)
>> record = User.new({ :login => 'quire', :email => '[email protected]', 
>> :password => 'quire', :password_confirmation => 'quire' })
=> #<User ... activation_code: nil, state: "passive" ...> # No 
activation code, state is passive

Why is the state passive? In my opinion it should be pending because of 
this line:

acts_as_state_machine :initial => :pending

And because in my opinion it should be pending, it should also have an 
activation code:

state :pending, :enter => :make_activation_code

However, it doesn't so far.

>> record.save
=> true
>> record
=> #<User ... activation_code: 
"996b495dcbb15a61cdda19ef5da07a78b27dff87", state: "pending" ... >

Well, after calling ActiveRecord's save method it seems to have changed 
to the pending state, and the activation_code is available. Looks quite 
good, so far.

In my opinion, the activation_code should now also be saved to the DB. 
So let's check this:

>> record.reload
=> #<User ... activation_code: nil, state: "pending" ... >

So here we have the problem! The activation_code is nil again! No idea 
why, but it's nil!

The only way to get this stuff to work is by calling the "register!" 
method:

josh$ script/console
Loading development environment (Rails 2.1.0)
>> record = User.new({ :login => 'quire', :email => '[email protected]', 
>> :password => 'quire', :password_confirmation => 'quire' })
=> #<User id: nil, first_name: nil, last_name: nil, login: "quire", 
email: "[email protected]", remember_token: nil, crypted_password: nil, 
password_reset_code: nil, salt: nil, activation_code: nil, 
remember_token_expires_at: nil, activated_at: nil, deleted_at: nil, 
state: "passive", created_at: nil, updated_at: nil>
>> record.register!
=> true
>> record
=> #<User ... activation_code: 
"f8395f836ec66c9db966da457ba19cdf5f29dd0a", state: "pending" ... >
>> record.reload
=> #<User ... activation_code: 
"d5402915503a0c3f1a9eb984c116bc0ae4c07877", state: "pending" ... > # The 
activation_code stays now

This doesn't make any sense to me. The only thing that "register!" does 
is changing the state from "passive" to "pending":

  event :register do
    transitions :from => :passive, :to => :pending, :guard => Proc.new 
{|u| !(u.crypted_password.blank? && u.password.blank?) }
  end

OK, this sounds reasonable, but then I don't understand, why and where 
the state is changed when calling save (it's exactly the same transition 
from "passive" to "pending" as when calling register!), and why the 
activation_code gets lost in this case...?

Looks everything really strange to me... You see my problem now?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to