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 Morin
http://www.cfcl.com/rdm/resume rdm-go8te9J4rpw@public.gmane.org
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Hi Rich, Rich Morin 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/13/06, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I got rid of the @ signs and went from strings to symbols,
but things are still broken:
At the end of the login method (user_controller.rb), I''m
setting values into session, then redirecting, as:
puts ">>>>> redirecting" #
TRACE
session[:user] = u.id
session[:foozle] = ''bar'' #{T}
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
else
puts ">>>>> session is undefined in get_user"
end
This prints out
>>>>> session is defined in get_user
>>>>> class = CGI::Session
>>>>> get_user: foozle is undefined
>>>>> session[:user] is undefined
Oh yeah:
% rails --version
Rails 1.1.6
-r
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume rdm-go8te9J4rpw@public.gmane.org
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-14 02:51 UTC
Re: @session is getting reset?
Hi -- On Fri, 13 Oct 2006, Jeremy Kemper wrote:> On 10/13/06, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> 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.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 | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Out of curiosity, I went looking for the session files. It looks like the
session information is getting stored, but not retrieved:
% L tmp/se*/*
-rw------- 1 rdm 69 Oct 13 20:46 tmp/sessions/ruby_sess.41ab9c6e783fb448
-rw------- 1 rdm 90 Oct 13 20:46 tmp/sessions/ruby_sess.d56b9b9cb629a50c
od -cx tmp/se*/*8
0000000 004 \b { 006 " \t h a s h { 006 " \n f
l
0408 7b06 2209 6861 7368 7b06 220a 666c
0000020 a s h I C : '' A c t i o n C o
n
6173 6849 433a 2741 6374 696f 6e43 6f6e
0000040 t r o l l e r : : F l a s h : :
7472 6f6c 6c65 723a 3a46 6c61 7368 3a3a
0000060 F l a s h H a s h { \0 006 : \n @ u
466c 6173 6848 6173 687b 0006 3a0a 4075
0000100 s e d { \0
7365 647b 0000
0000105
% od -cx tmp/se*/*c
0000000 004 \b { 006 " \t h a s h { \b : \v f o
0408 7b06 2209 6861 7368 7b08 3a0b 666f
0000020 o z l e " \b b a r : \t u s e r i
6f7a 6c65 2208 6261 723a 0975 7365 7269
0000040 006 " \n f l a s h I C : '' A c
t i
0622 0a66 6c61 7368 4943 3a27 4163 7469
0000060 o n C o n t r o l l e r : : F l
6f6e 436f 6e74 726f 6c6c 6572 3a3a 466c
0000100 a s h : : F l a s h H a s h { \0
6173 683a 3a46 6c61 7368 4861 7368 7b00
0000120 006 : \n @ u s e d { \0
063a 0a40 7573 6564 7b00
0000132
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume rdm-go8te9J4rpw@public.gmane.org
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Hi Rich, Rich Morin wrote:> > I got rid of the @ signs and went from strings to symbols, > but things are still broken:I''ve been through it and honestly can''t see the problem either. Sorry I can''t be more help. I do hope you''ll post what you find here, though. Something on the wiki would be cool too. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Fri, Oct 13, 2006, Rich Morin wrote:> I got rid of the @ signs and went from strings to symbols, > but things are still broken:I just copied/pasted your code into a test application, and it WORKSFORME. Either your environment is screwed up, or some code that you''re not showing us is breaking it. Try to copy exactly what you sent out into a new application and give it a go. You''ll have to change u.id to something else... if that works fine, then your session is getting munged somewhere else in your app. Ben --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
(coming into this conversation late..) possible write error(permissions) in your session folder? J On 14-Oct-06, at 8:18 PM, Ben Bleything wrote:> > On Fri, Oct 13, 2006, Rich Morin wrote: >> I got rid of the @ signs and went from strings to symbols, >> but things are still broken: > > I just copied/pasted your code into a test application, and it > WORKSFORME. Either your environment is screwed up, or some code that > you''re not showing us is breaking it. > > Try to copy exactly what you sent out into a new application and > give it > a go. You''ll have to change u.id to something else... if that works > fine, then your session is getting munged somewhere else in your app. > > Ben > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---