# \[Please help!\]store parameters variable into database

**URL:** <https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919>\
**Category:** Rails\
**Created:** [January 5, 2009, 11:23am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919 "2009-01-05T11:23:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 5, 2009, 11:23am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/1 "2009-01-05T11:23:51Z")

</div>

So here’s what I’m trying to do  
I’m going to store params variables into database.  
Here’s what it’s looklike.

## ------------------------Data that store on my database -------------- — !map:HashWithIndifferentAccess “15”: “1” “16”: “1” 2-Medium: “0” 1-High: “1” 3-Low: “0”

So I need to call this parameter from database then pass it on the page  
once again But It’s not like the previous parameter so any idea?

Please help!!

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 2:57am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/2 "2009-01-06T02:57:54Z")

</div>

Ukrit H. wrote:

> So here’s what I’m trying to do  
> I’m going to store params variables into database.  
> Here’s what it’s looklike.
> 
> ## ------------------------Data that store on my database -------------- — !map:HashWithIndifferentAccess “15”: “1” “16”: “1” 2-Medium: “0” 1-High: “1” 3-Low: “0”
> 
> So I need to call this parameter from database then pass it on the page  
> once again But It’s not like the previous parameter so any idea?
> 
> Please help!!

I’m still confused with this problem  
I wonder that,Can I convert this kind of variables back to params?

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 3:30am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/3 "2009-01-06T03:30:05Z")

</div>

One way is to save a serialized hash into the db and you can deserialize  
the saved hash object back to params.

Regards,

# rp8

> **[Competo Solutions, Inc.](https://competo.com/)**
>
> Sharing our experience in ever changing tech landscapes

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 3:35am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/4 "2009-01-06T03:35:32Z")

</div>

rp8 -\_- wrote:

> One way is to save a serialized hash into the db and you can deserialize  
> the saved hash object back to params.
> 
> Regards,
> 
> # rp8
> 
> [http://lun.competo.com](http://lun.competo.com)

How to serialize would you mind giving me some example.  
suppose that I’ve session[‘test’] which store several params inside  
such as  
session[‘test’] = idlist[‘1’]=test&idlist[‘2’]=test2

so I need to store this stuff inside my DB so if I need to serialized  
what I have to do?

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 3:44am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/5 "2009-01-06T03:44:17Z")

</div>

Ukrit H. wrote:

> rp8 -\_- wrote:
> 
> > One way is to save a serialized hash into the db and you can deserialize  
> > the saved hash object back to params.
> > 
> > Regards,
> > 
> > # rp8
> > 
> > [http://lun.competo.com](http://lun.competo.com)
> 
> How to serialize would you mind giving me some example.  
> suppose that I’ve session[‘test’] which store several params inside  
> such as  
> session[‘test’] = idlist[‘1’]=test&idlist[‘2’]=test2
> 
> so I need to store this stuff inside my DB so if I need to serialized  
> what I have to do?  
> require ‘yaml’

serialized = obj.to\_yaml  
new\_obj = YAML::load(serialized)  
puts new\_obj.width

Regards,

# rp8

> **[Competo Solutions, Inc.](https://competo.com/)**
>
> Sharing our experience in ever changing tech landscapes

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 9:14am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/6 "2009-01-06T09:14:21Z")

</div>

if those colons (“:”) are in the db, you have almost-readymade json.

-eric

On Jan 5, 7:05 pm, Ukrit H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 3:39pm UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/7 "2009-01-06T15:39:29Z")

</div>

> **[YAML vs Marshal performance](https://significantbits.wordpress.com/2008/01/29/yaml-vs-marshal-performance/)**
>
> A colleague of mine has built a quite sophisticated mechanism that allows for components to automatically reload if necessary in case a user interaction requires it. In order to do that though, it …

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 6, 2009, 4:05am UTC](https://www.ruby-forum.com/t/please-help-store-parameters-variable-into-database/156919/8 "2009-01-06T04:05:59Z")

</div>

rp8 -\_- wrote:

> Ukrit H. wrote:
> 
> > rp8 -\_- wrote:
> > 
> > > One way is to save a serialized hash into the db and you can deserialize  
> > > the saved hash object back to params.
> > > 
> > > Regards,
> > > 
> > > # rp8
> > > 
> > > [http://lun.competo.com](http://lun.competo.com)
> > 
> > How to serialize would you mind giving me some example.  
> > suppose that I’ve session[‘test’] which store several params inside  
> > such as  
> > session[‘test’] = idlist[‘1’]=test&idlist[‘2’]=test2
> > 
> > so I need to store this stuff inside my DB so if I need to serialized  
> > what I have to do?  
> > require ‘yaml’
> 
> serialized = obj.to\_yaml  
> new\_obj = YAML::load(serialized)  
> puts new\_obj.width
> 
> Regards,
> 
> # rp8
> 
> [http://lun.competo.com](http://lun.competo.com)

Thx here’s what’s store inside my db for now

* * *

## — !map:HashWithIndifferentAccess 2-Medium: “1” “17”: “1” “18”: “1” 3-Low: “1” 1-High: “1” “20”: “0” “19”: “1”

It’s that correct one? if so how can I call this one back to  
session[‘test’] ?
