Saving an Array to MySQL... data changes

I have a multiple select menu:

<%= select_tag ‘resume[employer_1_industry][]’,
options_for_select(industries_helper, @resume.employer_1_industry),
:multiple=> true %>

It produces this HTML:

- Select - Electrical Engineering - Analog Electrical Engineering - Digital Electrical Engineering - RF

When I process the form the array from the multiple select produced is:

[“1”, “3”] or whatever the options are that I select. The problem seems
to be when I process the form. MySQL saves the array as:


  • “1”
  • “3”

I have the column set to ‘text’ datatype. I have tried everything from
forcing the column back to an array (.to_a) to forcing it to a string
before it is written to MySQL but nothing seems to work. The data can’t
be read back into my app properly. Any help?

I found the answer… must serialize the column data in the model…

serialize :employer_1_industry, Array

Brian C. wrote:

I have a multiple select menu:

<%= select_tag ‘resume[employer_1_industry][]’,
options_for_select(industries_helper, @resume.employer_1_industry),
:multiple=> true %>

It produces this HTML:

- Select - Electrical Engineering - Analog Electrical Engineering - Digital Electrical Engineering - RF

When I process the form the array from the multiple select produced is:

[“1”, “3”] or whatever the options are that I select. The problem seems
to be when I process the form. MySQL saves the array as:


  • “1”
  • “3”

I have the column set to ‘text’ datatype. I have tried everything from
forcing the column back to an array (.to_a) to forcing it to a string
before it is written to MySQL but nothing seems to work. The data can’t
be read back into my app properly. Any help?

I don’t understand why your using an array. Why not use a relational
model, with an employers table and an industries table, then a habtm
join using an employers_industries table?
-N

I don’t need a relational model here… just saving simple data.

unknown wrote:

I don’t understand why your using an array. Why not use a relational
model, with an employers table and an industries table, then a habtm
join using an employers_industries table?
-N