@session is getting reset?

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 Rich M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

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

On 10/13/06, Bill W. [email protected] 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

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 :slight_smile:

$ 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 | [email protected]
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs