Bryce wrote:> I''ve been banging my head against a wall on this one for awhile. I
> could really use the groups help on this one.
>
> I need to make a dynamic associative array. I would like to store this
> array in a session variable for future access and to keep my DB
> overhead low. I think it makes sense to take this form:
> session[:dyn] ||= []
> session[:dyn]
> - visit_123
> - title: "A title of this thing"
> - reports:
> - 1
> - 2
> -3
> - visit_456
> - title: "Another thing"
> - reports:
> - 4
> - 78
> -25
>
> In my mind, the session becomes an associative array and the user
> selected stuff gets inserted into it. The problem is coding it.
I''ve
> come up with this so far:
>
> h[params[:unq_id]] = {:reports => [1,2,3,4] , :title => params[:vi]
> [:title]}
> session[:dyn] = h[params[:unq_id]]
>
> The problem is, when the params[:unq_id] changes , the whole session
> is replaced by the new hash instead of being added to it. I''ve
tried
> << and += to know avail.
>
> thanks in advance for your help,
> Bryce
>
Try:
> session[:dyn].update(params[:unq_id] => {:reports => [1,2,3,4] ,
:title => ''something''})
But ultimately you should avoid storing too much data in the session, as
a properly indexed database will be faster.
Zsombor
--
Company - http://primalgrasp.com
Thoughts - http://deezsombor.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---