Forum: Ruby on Rails associative array

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A4137000ca3c718424e811cd7511c50b?d=identicon&s=25 Bryce (Guest)
on 2007-02-22 00:53
(Received via mailing list)
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] ||= []
    - visit_123
            - title: "A title of this thing"
           - reports:
                  - 1
                 - 2
    - visit_456
            - title: "Another thing"
           - reports:
                  - 4
                 - 78

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]
    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,
15619be638a3ae3d6f86a4995c6484c1?d=identicon&s=25 Dee Zsombor (Guest)
on 2007-02-22 09:49
(Received via mailing list)
Bryce wrote:
>            - reports:
> In my mind, the session becomes an associative array and the user
> thanks in advance for your help,
> Bryce


>  session[:dyn].update(params[:unq_id] => {:reports => [1,2,3,4] , :title => 

But ultimately you should avoid storing too much data in the session, as
a properly indexed database will be faster.


Company  -
Thoughts -
This topic is locked and can not be replied to.