# Having problems with serialize :column\_name

**URL:** <https://www.ruby-forum.com/t/having-problems-with-serialize-column-name/127555>\
**Category:** Rails\
**Created:** [January 30, 2008, 11:22am UTC](https://www.ruby-forum.com/t/having-problems-with-serialize-column-name/127555 "2008-01-30T11:22:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kennylovrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d9b06d/32.png) [@kennylovrin](https://www.ruby-forum.com/u/kennylovrin)\
**Post date:** [January 30, 2008, 11:22am UTC](https://www.ruby-forum.com/t/having-problems-with-serialize-column-name/127555/1 "2008-01-30T11:22:30Z")

</div>

Hi guys

I have asked this questions on the Rails Forum as well, but haven’t  
got any reply, so I will try here.

The thing is this:

I want to store “portlets” in a Portlet model in the db. I want to  
store them togheter as they are the same kind of data in a way, but  
there are different variateions of a portlet. They only have one db  
column in common, the rest can vary a lot. So to do this I would like  
to store the rest of the data in one single column.

What I have done to do this is the following:

1. The model Portlet contains the columns id, name, portlettype\_id &  
hash\_value. The value in portlettype\_id will decide what has to be  
stored in the hash\_value column. Reading from the docs, I have also  
put “serialize :hash\_value” in the class code.

2. So in my new action in my PortletsController I just do @portlet =  
Portlet.new

3. In my new.html.erb I have done the following (I’m leaving out some  
formatting specific html in this example):  
\<% form\_for @project do |f| %\>  
\<%= f.text\_field :name %\>  
\<%= f.collection\_select :portlettype\_id, … %\>  
\<% fields\_for "portlet[hash\_value] do |hf| %\>  
\<%= hf.text\_field :heading %\>  
\<%= hf.text\_area :body %\>  
\<% end %\>  
\<% end %\>

4. Everything renders nice and I do get inputs with name  
portlet[hash\_value][heading] etc.

5. When I submit, the development log shows “hash\_value” =\>  
{ “heading” =\> “text”} in the params hash, so it does seem to me that  
I do get the hash\_value containing a hash itself.

6. When I save, the name and portlettype\_id fields get saved  
correctly, but in the hash\_value column i get !  
map:HashWithIndifferentAccess

It seems to me that I must be doing something wrong, because when I  
read about serialize in the api docs, it sounds like it would do  
exactly what I’m after.

Any ideas? I would be glad to supply you with more info, as I badly  
want to solve this problem.

Thanks  
Kenny
