# Session\[:aa\]\[:bb\]

**URL:** <https://www.ruby-forum.com/t/session-aa-bb/158137>\
**Category:** Rails\
**Created:** [January 19, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137 "2009-01-19T19:05:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 7:05pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/1 "2009-01-19T19:05:27Z")

</div>

Why this doesn’t work?

session[:aa][:bb] = “xxx”

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/2 "2009-01-19T19:15:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/3 "2009-01-19T19:39:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 9:53pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/4 "2009-01-19T21:53:23Z")

</div>

I can’t make this work:

@tmp = “xxx”  
session[@tmp][:yyy] = “zzz”

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 8:39pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/5 "2009-01-19T20:39:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 19, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/session-aa-bb/158137/6 "2009-01-19T22:01:31Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
