Forum: Ruby on Rails session[:aa][:bb]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-01-19 20:05
Why this doesn't work?

session[:aa][:bb] = "xxx"
Frederick C. (Guest)
on 2009-01-19 20:15
(Received via mailing list)
On 19 Jan 2009, at 18:05, James B. wrote:

>
> Why this doesn't work?
>
> session[:aa][:bb] = "xxx"

probably because session[:aa] is nil

Fred
Fresh M. (Guest)
on 2009-01-19 20:39
Frederick C. wrote:
> On 19 Jan 2009, at 18:05, James B. wrote:
>
>>
>> Why this doesn't work?
>>
>> session[:aa][:bb] = "xxx"
>
> probably because session[:aa] is nil
>
> Fred


How to "fix" it?


index 25009 out of string
Frederick C. (Guest)
on 2009-01-19 21:39
(Received via mailing list)
On 19 Jan 2009, at 18:39, James B. wrote:

>>
>> Fred
>
>
> How to "fix" it?

>
> index 25009 out of string

that sounds like session[:aa] is a string.
There's nothing wrong with session[:aa][:bb] = "xxx" assuming the
objects involved are of the right type, which will be down to the rest
of the code in your app

Fred
Fresh M. (Guest)
on 2009-01-19 22:53
I can't make this work:

@tmp = "xxx"
session[@tmp][:yyy] = "zzz"
Rob B. (Guest)
on 2009-01-19 23:01
(Received via mailing list)
On Jan 19, 2009, at 3:53 PM, James B. wrote:
> I can't make this work:
>
> @tmp = "xxx"
> session[@tmp][:yyy] = "zzz"


and unless you tell us what you expect to happen, no one else can
either. ;-)

Do you expect the Hash implied by session[@tmp] to spring into
existence so you can assign a value to the :yyy key?

In that case, session would have to refer to something like:

   Hash.new {|h,k| h[k] = {} }

So:
   session = Hash.new {|h,k| h[k] = {} }
   @tmp = "xxx"
   session[@tmp][:yyy] = "zzz"

   puts session.inspect

{"xxx"=>{:yyy=>"zzz"}}

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
This topic is locked and can not be replied to.