# Storing hashes in DB but getting strings back

**URL:** <https://www.ruby-forum.com/t/storing-hashes-in-db-but-getting-strings-back/103151>\
**Category:** Rails\
**Created:** [May 2, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/storing-hashes-in-db-but-getting-strings-back/103151 "2007-05-02T13:06:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 2, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/storing-hashes-in-db-but-getting-strings-back/103151/1 "2007-05-02T13:06:21Z")

</div>

Hi!  
I am adding a hash to a serialized column in a DB. When retrieving the  
data I get back a string though… Any idea why that might happen?

Here is the model and a copy and paste of the usage from irb:  
[http://pastie.caboo.se/58220](http://pastie.caboo.se/58220)

Hope you have any ideas!

Best regards  
Sebastian

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 2, 2007, 1:19pm UTC](https://www.ruby-forum.com/t/storing-hashes-in-db-but-getting-strings-back/103151/2 "2007-05-02T13:19:53Z")

</div>

I solved the problem.  
Never mind.  
I had written the serialize statement wrong.

I had written:  
serialize :name1, :name2

but writing  
serialize :name1, Hash  
serialize :name2, Hash

solved the problem.  
Tralala!

Thanks

S

Sebastian probst Eide wrote:

> Hi!  
> I am adding a hash to a serialized column in a DB. When retrieving the  
> data I get back a string though… Any idea why that might happen?
> 
> Here is the model and a copy and paste of the usage from irb:  
> [Parked at Loopia](http://pastie.caboo.se/58220)
> 
> Hope you have any ideas!
> 
> Best regards  
> Sebastian
