# Restful Authentication and State Machine state transfer question

**URL:** <https://www.ruby-forum.com/t/restful-authentication-and-state-machine-state-transfer-question/148065>\
**Category:** Rails\
**Created:** [September 8, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-state-machine-state-transfer-question/148065 "2008-09-08T22:29:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 8, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-state-machine-state-transfer-question/148065/1 "2008-09-08T22:29:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 8, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-state-machine-state-transfer-question/148065/2 "2008-09-08T23:13:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 8, 2008, 11:29pm UTC](https://www.ruby-forum.com/t/restful-authentication-and-state-machine-state-transfer-question/148065/3 "2008-09-08T23:29:20Z")

</div>

> 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.
