# Problems with session store and local host

**URL:** <https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507>\
**Category:** Rails\
**Created:** [December 12, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507 "2008-12-12T18:03:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [December 12, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507/1 "2008-12-12T18:03:59Z")

</div>

Rails 2.2.2  
Ruby 1.8.6

I am developing an application that uses a gem for authentication. When  
I try and add a new user then the rails code within the gem enters an  
infinite loop. The author is working on this issue but I would like to  
obtain the benefit of your collective experience.

Given  
map.resource :account, :controller =\> ‘users’  
map.resource :user\_session  
map.resources :users

# GET /users/new

# GET /users/new.xml

def new  
@user = User.new(params[:user])  
if @user.save  
flash[:notice] = ‘User Account Added’  
redirect\_back\_or\_default account\_url  
else  
render :action =\> new  
end  
end

# POST /users

# POST /users.xml

def create  
@user = User.new(params[:user])

```
respond_to do |format|
  if @user.save
    flash[:notice] = 'User was successfully created.'
    format.html { redirect_to(@user) }
    format.xml { render :xml => @user, :status => :created,

```

:location =\> @user }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @user.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

Here is what happens when the server tries to reach  
localhost:3000/account/new

CACHE (0.0ms) SELECT “users”.id FROM “users” WHERE (“users”.“login”  
IS NULL) LIMIT 1  
User Exists (0.7ms) SELECT “users”.id FROM “users” WHERE  
(“users”.“perishable\_token” = ‘MNrVzl2G5B3AiVl8d3M2’) LIMIT 1  
User Exists (0.4ms) SELECT “users”.id FROM “users” WHERE  
(“users”.“persistence\_token” =  
‘d0357dc4dd2660ae35cdc910a8b9084d4146f3f590722ae683efd974c22095dedba100af859a15a442621444114fa1cd5d66bff0a62f6585f715de9b1de33429’)  
LIMIT 1  
CACHE (0.0ms) SELECT “users”.id FROM “users” WHERE (“users”.“login”  
IS NULL) LIMIT 1  
User Exists (0.6ms) SELECT “users”.id FROM “users” WHERE  
(“users”.“perishable\_token” = ‘1Vyz36vPA5frHn8J0XII’) LIMIT 1  
User Exists (0.5ms) SELECT “users”.id FROM “users” WHERE  
(“users”.“persistence\_token” =  
‘b2e81093c5ca6a9078b08077fdd8fee8d3a4d4a9d7a299316ac8a15f4a9ea5c6af649800f1b52ad546c6e099d4b7720906b9ef091d224c09b35cc6c29debc333’)  
LIMIT 1

I infer from this that when the user is null, as is the case with a new  
user, then the gem code sets two session tokens that it then checks in  
its database. The conclusion that I reach is that the client user  
session is not getting these values set by the application and that, as  
the user login value remains null, the process repeats ad infinitum.  
The question becomes: why are tokens not being set in the session?

I ran across this thread [Pragmatic Bookshelf: By Developers, For Developers](http://forums.pragprog.com/forums/43/topics/276)  
and wonder if I may have encountered a related problem.

The problem arises whether I use cookie based sessions or AR based  
sessions.

Has anyone else run across this type of problem? How was it resolved.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [December 12, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507/2 "2008-12-12T18:14:35Z")

</div>

On 12 Dec 2008, at 17:03, James B. wrote:

> obtain the benefit of your collective experience.  
> which gem ? You haven’t really shown us anything much beyond what a  
> standard scaffolded model would look like.  
> What is the actual code responsible from the log excerpt you pasted  
> below? In addition it would be helpful to see what happened before it  
> got stuck in a loop.

Fred

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [December 12, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507/3 "2008-12-12T20:54:51Z")

</div>

Frederick C. wrote:

> On 12 Dec 2008, at 17:03, James B. wrote:
> 
> > obtain the benefit of your collective experience.  
> > which gem ? You haven’t really shown us anything much beyond what a  
> > standard scaffolded model would look like.  
> > What is the actual code responsible from the log excerpt you pasted  
> > below? In addition it would be helpful to see what happened before it  
> > got stuck in a loop.
> 
> Fred

I would rather not publicize the gem name since that might be taken as a  
public criticism. I changed the users/new controller call from save to  
save! and what turned up was a bunch of model validation errors. The  
loop was caused by the controller simply re-rendering the form when the  
save failed. evidently there is some problem causing the the model  
validations to be checked before the input form template is rendered. I  
have communicated this to the gem author.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [December 12, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507/4 "2008-12-12T21:16:30Z")

</div>

On 12 Dec 2008, at 19:54, James B. wrote:

> > Fred
> 
> I would rather not publicize the gem name since that might be taken  
> as a  
> public criticism.  
> Come, on this is open source after all 🙂 Besides I reckon the gem in  
> question is authlogic

Fred

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [December 15, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/problems-with-session-store-and-local-host/155507/5 "2008-12-15T16:00:00Z")

</div>

Frederick C. wrote:

> Come, on this is open source after all 🙂

Yes, but the problem was with my code, not his.

def new  
@user = User.new(params[:user])  
if @user.save  
flash[:notice] = ‘User Account Added’  
redirect\_back\_or\_default account\_url  
else  
render :action =\> new  
end  
end

Should have been.

def new  
@user = User.new  
end

Somehow I ended up coding a create method and labelling it as new.
