Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

My Booking model has: serialize :custom_data, Hash
From the console it works as expected saving values to the custom_data
attribute.
But when having a form with parameters like
this: booking[custom_data][hello] and creating a new object in the
controller like this: Booking.new( params[:booking] ), values are saved
in
the database with added metadata like this: ---
!ruby/hash:ActiveSupport::HashWithIndifferentAccess
How can get rid of the HashWithIndifferentAccess-metadata when saving
from
a form?

I fixed it by converting it to a hash:
@booking.custom_data = params[:booking][:custom_data].to_hash if
params[:booking][:custom_data]
I do think that Rails should handle this automatically though. There is
no
way to see this error by just using rails. You have to look at the
actual
data stored in the database to see that it stores more than just the
actual
data. I would suspect there are more people saving serialised attributes
from a form and will have this issue without realising it.

On Friday, 1 June 2012 09:15:18 UTC-4, Espen Antonsen wrote:
>>
I don't follow that logic at all. If you're interacting with a
serialized
column by any other means than loading it from the DB as a Ruby object,
you
are DOING IT WRONG. If you really, really want to interact with hashes
in
the DB, check out things like Postgres's Hstore:
http://www.postgresql.org/docs/9.0/static/hstore.html
--Matt Jones