# Restful authentication help : updates never reach database

**URL:** <https://www.ruby-forum.com/t/restful-authentication-help-updates-never-reach-database/186662>\
**Category:** Rails\
**Created:** [April 10, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/restful-authentication-help-updates-never-reach-database/186662 "2010-04-10T22:36:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![djconcepcion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@djconcepcion](https://www.ruby-forum.com/u/djconcepcion)\
**Post date:** [April 10, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/restful-authentication-help-updates-never-reach-database/186662/1 "2010-04-10T22:36:32Z")

</div>

my setup:  
OS X 10.6.3  
rails (2.3.5)  
sqlite

the problem: moving this old code to a new project (I didn’t want to  
hunt down yet-another-authentication module as I can’t tell what is  
abandoned or not, I figured copy paste would be the quickest - no such  
luck), basic user authentication is broken.  
I found several and fixed several pieces of broken code, but now I am  
stuck at:  
ActiveRecord refuses to save changes to the User model, in particular:  
when the acs\_as\_state\_machine has changed the value.

e.g. this state machine will call a Model method:  
def make\_activation\_code  
self.activation\_code= …  
end

as a result of a state change (from \<non existent | passive state\> -\>  
pending

A state change occurs on object create, but, ironically, thanks to  
acts\_as\_state\_machine’s plugin setup, AFTER the object has already been  
stored into the database.

The original code had a  
u = User.new(…)  
u.register!  
…  
etc.

all of which would store nothing at all the the database (this was raw  
original generator code unmodified, and used to work)

I then tried:  
u = User.create() (force the object creation)  
…

and  
u = User.new(…)  
u.register!  
u.save!  
u.save(false)

the latter lines with printouts confirm the u finally has the right  
activation code (in this case, after save!, because  
acts\_as\_state\_machine latches onto after\_create, and THEN plops in the  
authentication\_code) … alas, save(false, or any subsequent calls to  
save, and the setting of the authentication\_code inside the model fail  
to update the database, and these changes to the object are lost  
forever…

What am I missing?

---

<div class="post-metadata">

**Author:** ![djconcepcion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@djconcepcion](https://www.ruby-forum.com/u/djconcepcion)\
**Post date:** [April 10, 2010, 10:38pm UTC](https://www.ruby-forum.com/t/restful-authentication-help-updates-never-reach-database/186662/2 "2010-04-10T22:38:40Z")

</div>

DJ Cole wrote:

> my setup:  
> save(false)
> 
> acts\_as\_state\_machine latches onto after\_create, and THEN plops in the  
> authentication\_code) … alas, save(false, or any subsequent calls to

That should read “activation\_code …”
