# @session is getting reset?

**URL:** <https://www.ruby-forum.com/t/session-is-getting-reset/72091>\
**Category:** Rails\
**Created:** [October 14, 2006, 1:58am UTC](https://www.ruby-forum.com/t/session-is-getting-reset/72091 "2006-10-14T01:58:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [October 14, 2006, 1:58am UTC](https://www.ruby-forum.com/t/session-is-getting-reset/72091/1 "2006-10-14T01:58:46Z")

</div>

I’m using r4rmusic (from “Ruby for Rails”) as the basis for a  
hangman game, but I appear to have broken something. For  
some reason, @session is not retaining values for me.

At the end of the login method (user\_controller.rb), I’m  
setting values into @session, then redirecting, as:

```
  puts ">>>>> redirecting" # TRACE
  @session['foozle'] = 'bar'
  if (@session['foozle'])
    puts ">>>>> login: foozle = '#{@session['foozle']}'"
  else
    puts ">>>>> login: foozle is undefined"
  end

  redirect_to :controller => 'main',
              :action => 'welcome'

```

This prints out

> > > > > redirecting  
> > > > > login: foozle = ‘bar’

Then, in get\_user (application.rb), I try to retrieve them:

```
if (@session)
  puts ">>>>> @session is defined in get_user"
  puts ">>>>> class = #{@session.class}"

  if (@session['foozle'])
    puts ">>>>> get_user: foozle = '#{@session['foozle']}'"
  else
    puts ">>>>> get_user: foozle is undefined"
  end

```

This prints out

> > > > > @session is defined in get\_user  
> > > > > class = CGI::Session  
> > > > > get\_user: foozle is undefined

I haven’t a clue how to debug this. Help?

## -r

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [October 14, 2006, 2:48am UTC](https://www.ruby-forum.com/t/session-is-getting-reset/72091/2 "2006-10-14T02:48:48Z")

</div>

Hi Rich,

Rich M. wrote:

> @session is not retaining values for me.

You don’t say what version of Rails you’re using, but if it’s recent,  
the  
problem could be that ‘@session’ is no longer a supported way of  
referencing  
the session hash. Use ‘:session’ instead. The ‘@’ prefix denotes an  
instance variable. Moving to :session reduces confusion.

hth,

Bill

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [October 14, 2006, 3:16am UTC](https://www.ruby-forum.com/t/session-is-getting-reset/72091/3 "2006-10-14T03:16:52Z")

</div>

On 10/13/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > @session is not retaining values for me.
> 
> You don’t say what version of Rails you’re using, but if it’s recent, the  
> problem could be that ‘@session’ is no longer a supported way of  
> referencing  
> the session hash. Use ‘:session’ instead. The ‘@’ prefix denotes an  
> instance variable. Moving to :session reduces confusion.

@session and the other instance variables are deprecated but still  
supported. You’ll see warnings galore until you update your code, but no  
breakage. Use the session method (:session is a symbol, not a method  
call)  
rather than the @session instance variable.

Best,  
jeremy

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [October 14, 2006, 4:53am UTC](https://www.ruby-forum.com/t/session-is-getting-reset/72091/4 "2006-10-14T04:53:07Z")

</div>

Hi –

On Fri, 13 Oct 2006, Jeremy K. wrote:

> @session and the other instance variables are deprecated but still  
> supported. You’ll see warnings galore until you update your code, but no  
> breakage.

And sometimes after you update your code 🙂

$ for f in `find app -type f -not -path "*svn*"`;  
do grep “@flash” $a; done  
$ cd test/integration  
$ ruby user\_changes\_profile\_test.rb  
Loaded suite user\_changes\_profile\_test  
Started  
DEPRECATION WARNING: @flash is deprecated! Call flash.[] instead of  
@flash.[].

# etc.

This is on edge (r. 5271). I haven’t dug into where it’s coming from  
yet.

David

–  
David A. Black | removed\_email\_address@domain.invalid  
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]  
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]  
[1] [Ruby for Rails](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
[2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)
