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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-19 19:05
Why this doesn't work?

session[:aa][:bb] = "xxx"
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-19 19:15
(Received via mailing list)
On 19 Jan 2009, at 18:05, James Bond wrote:

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

probably because session[:aa] is nil

Fred
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-19 19:39
Frederick Cheung wrote:
> On 19 Jan 2009, at 18:05, James Bond 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-19 20:39
(Received via mailing list)
On 19 Jan 2009, at 18:39, James Bond 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
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-19 21:53
I can't make this work:

@tmp = "xxx"
session[@tmp][:yyy] = "zzz"
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-01-19 22:01
(Received via mailing list)
On Jan 19, 2009, at 3:53 PM, James Bond 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 Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.