Associative array

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

Bryce wrote:

       - reports:

In my mind, the session becomes an associative array and the user

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