On Apr 20, 2:55 pm, Joshua Muheim <rails-mailing-l...@andreas-s.net>
wrote:
> Fernando Perez wrote:
> >> I guess it has something to do with acts_as_state_machine?
>
> > Yes. Don't you read the source code of your plugins before using them?
> > That's bold.
>
> OK, I read some of the source code of the plugin. Sadly I'm no very
> experienced Ruby programmer, so I have a question.
>
> Where does a new record get saved to the DB when calling register!?
>
> >> record = User.new({ :login => 'quire', :email => 'qu...@example.com', 
> >> :password => 'quire', :password_confirmation => 'quire' })
>
> => #<User id: nil, first_name: nil, last_name: nil, login: "quire",
> email: "qu...@example.com", 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.new_record?
> => true
> >> record.register!
> => true
> >> record.new_record?
>
> => false
>
> I'm trying to get into this plugin, but it seems very tricky to me...
> --
> Posted viahttp://www.ruby-forum.com/.


The record gets saved by aasm (acts_as_state_machine). By using this
plugin, your model has different "states" that is stored most likely
in a :state column. When you call register or register! on your model,
it is telling aasm to change the state of your model:

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

In this case, it's changing your model from the :passive state to
the :pending state. What happens at this point is that
make_activation_code is called because of this line:

state :pending, :enter => :make_activation_code.

Your model is saved after you call register because aasm changes the
state of the model and then saves that model.

Hopefully this helps.

Jon
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to