Restful Authentication and State Machine state transfer question

I’m adding some code to a project using restful_authentication and
acts_as_statemachine

In the create method for a user there is the following code generated
by the restful_authentication template

@user.regster! if user.valid?

And this will save and the user record if it is valid. I understand
that the statemachine will then change the state from passive to
pending. It will guard against this by validating that the
crypted_password and password getters are not blank. This I
understand. I am not seeing anything in the code that actually does an
ActiveRecord::Base.save on it. restful_authentication seems to be
pretty much just generated templates and I cannot find any code that
saves the record and there doesn’t seem to be anything in
acts_as_statemachine that recognizes this particular state change and
saves the record. Perhaps I am missing something or maybe there is
something else going on that saves the record. I don’t see any type of
observer running that will save the record upon a state change. I
understand the purpose of state machines but for whatever reason I
just cannot see how this plugin is saving the record. Any help would
be appreciated.

  • Brian C.

Nevermind…

In the acts_as_statemachine plugin the dynamically generated event
methods make a call to ‘fire’ which in turn makes a call to ‘perform’
which does an ‘update_attribute’ against the record which does a save
on the record. I hope this helps somebody else.

  • Brian C.

ActiveRecord::Base.save on it. restful_authentication seems to be
pretty much just generated templates and I cannot find any code that
saves the record and there doesn’t seem to be anything in
Actually restful_authentication is not simply a code generator when
using acts_as_state_machine or aasm. It does actually call into code
within the plugin to perform the state changes and update the database.

At least I think it’s the case with acts_as_state_machine. The project I
am currently working on is using aasm rather than the older
act_as_state_machine.

In my case I have this line at the top of my User model along with a few
other includes:
include Authorization::AasmRoles

So this is where all the state machine magic is happening.

Brian C. wrote:

I’m adding some code to a project using restful_authentication and
acts_as_statemachine

In the create method for a user there is the following code generated
by the restful_authentication template

@user.regster! if user.valid?

And this will save and the user record if it is valid. I understand
that the statemachine will then change the state from passive to
pending. It will guard against this by validating that the
crypted_password and password getters are not blank. This I
understand. I am not seeing anything in the code that actually does an
ActiveRecord::Base.save on it. restful_authentication seems to be
pretty much just generated templates and I cannot find any code that
saves the record and there doesn’t seem to be anything in
acts_as_statemachine that recognizes this particular state change and
saves the record. Perhaps I am missing something or maybe there is
something else going on that saves the record. I don’t see any type of
observer running that will save the record upon a state change. I
understand the purpose of state machines but for whatever reason I
just cannot see how this plugin is saving the record. Any help would
be appreciated.

  • Brian C.