Help with serialization

in my migration is have:

 t.string   :options

in my model i have:

 serialize :options

in my controller create and update I am doing the following:

@vehicle.options = {:ac_front => params[:ac_front],
:ac_rear => params[:ac_rear],
:air_bag_driver => params[:air_bag_driver],
:air_bag_passenger => params[:air_bag_passenger],
:air_bag_side => params[:air_bag_side],
:alloy_wheels => params[:alloy_wheels] }

where all the params being passed are boolean true or false values.

But for some reasons the values of the params do not get saved in the
db. What am i doing wrong?

I think the column you use for serializing should be a text column.

Try this in your migration:

t.text :options

Tim S. wrote in post #1000366:

I think the column you use for serializing should be a text column.

Try this in your migration:

t.text :options

I was following the info provided on this page.

http://railsforum.com/viewtopic.php?id=22651

and it states that it must be String. Though I tried it with String and
Text both and the result was the same. Something else must be an issue.

I’ve always used Text, otherwise, you’re mighty limited in what you
can store there. Never had any problem with it, either.

Walter

On May 23, 12:23pm, QAS WM [email protected] wrote:

@vehicle.options = {:ac_front => params[:ac_front],
:ac_rear => params[:ac_rear],
:air_bag_driver => params[:air_bag_driver],
:air_bag_passenger => params[:air_bag_passenger],
:air_bag_side => params[:air_bag_side],
:alloy_wheels => params[:alloy_wheels] }

where all the params being passed are boolean true or false values.

So what does get saved in the database. What does the params hash look
like at the point where this code runs?

Fred

On 23 May 2011 17:18, QAS WM [email protected] wrote:

:ac_rear => params[:ac_rear]

with true or false

:ac_rear => true,

that does get saved and shows as such.

Then it is nothing to do with the serialization, it is params that is
not setup at the point you assign it to @vehicle.options. Look in
development.log to see what params are being posted. If you can’t get
to the bottom of it then probably best to start a new thread as the
subject line is now inappropriate.

Colin

Frederick C. wrote in post #1000379:

So what does get saved in the database. What does the params hash look
like at the point where this code runs?

Fred

Values for each of the items in the hash are nil. If I replace the
params[:ac_rear] for example

:ac_rear => params[:ac_rear]

with true or false

:ac_rear => true,

that does get saved and shows as such.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs