In the Agile WD book it states regarding sesion data- "Rails uses the cookie-based approach". This can''t be entirely true can it ? Not that I''m complaining if it was but isn''t there some equivalent to say, PHP sessions ? Or am I wrong. Stuart -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060608/5e7255b7/attachment.html
> This can''t be entirely true can it ? Not that I''m complaining if it was but isn''t there some equivalent to say, PHP sessions ? Or am I wrong.No, no. It means Rails uses a cookie to identify your session. Just like PHP. The actual session data is, of course, stored on the server, not inside the cookie (which I assume is what you were thinking.) - Hendrik -- http://www.mans.de
Yes, I was thinking session data was stored in cookie. I''ve been working through the example though and get it now. Actually the example in the book stores the session data in a table. Stuart On 6/8/06, Hendrik Mans <hendrik@mans.de> wrote:> > > This can''t be entirely true can it ? Not that I''m complaining if it was > but isn''t there some equivalent to say, PHP sessions ? Or am I wrong. > > No, no. It means Rails uses a cookie to identify your session. Just > like PHP. The actual session data is, of course, stored on the server, > not inside the cookie (which I assume is what you were thinking.) > > - Hendrik > > -- > http://www.mans.de > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060608/dfccfc18/attachment.html
Okay I put this into my controller [code] if @session[''layout''] == 1 layout ''main'' elsif @session[''layout''] == 2 layout ''main2'' else layout ''main'' end [/code] In the app. [code] @session[''layout''] = 1 if @session[''layout''] == nil [/code] it says ''You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.[]'' What am I doing wrong? -- Posted via http://www.ruby-forum.com/.
Mohammad wrote:> Okay I put this into my controller > [code] > if @session[''layout''] == 1 > layout ''main'' > elsif @session[''layout''] == 2 > layout ''main2'' > else > layout ''main'' > end > [/code] > In the app. > [code] > @session[''layout''] = 1 if @session[''layout''] == nil > [/code] > > > it says ''You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.[]'' > What am I doing wrong?Try using "session[:key]" instead of "@session[''key'']", using the instance variable directly is deprecated. Also what line exactly is causing the error? with so many references of the session hash it would be good know exactly which one is crashing it. Hard to troubleshoot otherwise. Lastly a slightly cleaner way to do this:> session[:layout] = 1 if session[:layout] == nilWould be this:> session[:layout] = 1 if session[:layout].nil?Or even better:> session[:layout] = 1 unless session[:layout]But in my opinion the best way is:> session[:layout] ||= 1-- Posted via http://www.ruby-forum.com/.
On 6/23/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote:> > Mohammad wrote: > > Okay I put this into my controller > > [code] > > if @session[''layout''] == 1 > > layout ''main'' > > elsif @session[''layout''] == 2 > > layout ''main2'' > > else > > layout ''main'' > > end > > [/code] >if @session[''layout''] has not been defined or initialized you will get this error. So, before you test @session[''layout''] == 1 you need to check for @session[''layout''].nil? Something like: if @session[''layout''].nil? layout = ''main'' #and initialize @session[''layout''] to something for later checks elsif @session[''layout''] == 1 layout = ''main'' elsif @session[''layout''] == 2 layout = ''main2'' end One question...instead of storing the numbers why not store ''main'' and ''main2'' in @session[''layout'']? -- Andrew Stone -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060623/0fdba20a/attachment.html
Alex Wayne wrote:> Also what line exactly is causing the error? with so many references of > the session hash it would be good know exactly which one is crashing it. > Hard to troubleshoot otherwise.I change all of them to @session[''layout''] but now, [error]Symbol as array index[/error] -- Posted via http://www.ruby-forum.com/.
Mohammad wrote:> Alex Wayne wrote: >> Also what line exactly is causing the error? with so many references of >> the session hash it would be good know exactly which one is crashing it. >> Hard to troubleshoot otherwise. > > I change all of them to @session[''layout''] but now, > [error]Symbol as array index[/error]"session" should be a hash not an array. Are you overriding the sesion object somewhere? What I mean is you should never do: session = {:foo => ''bar''} but instead do session[:foo] = ''bar'' if you let rails manage the creation of the session, it should be a hash, not an array. -- Posted via http://www.ruby-forum.com/.