session[:aa][:bb]

Why this doesn't work?

session[:aa][:bb] = "xxx"

Why this doesn't work?

session[:aa][:bb] = "xxx"

probably because session[:aa] is nil

Fred

Frederick Cheung wrote:

Frederick Cheung 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

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

and unless you tell us what you expect to happen, no one else can either. :wink:

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