0

I am trying to save data from a dynamic form where the response saved can be either an array, or a string.

Using serialize in my model or using ':question_answer => []' in my permit tries to set every entry as an array. I need this to dynamically allow saving either as a string or an array to the MySQL DB.

Any help would be appreciated.

Midwire
  • 1,090
  • 8
  • 25
Will Ross
  • 25
  • 1
  • 8
  • This seems to be a duplicate question with a good answer here: http://stackoverflow.com/a/21315340/260670 – Midwire May 25 '16 at 18:20

1 Answers1

0

it's never a good way to save arrays in one column/field

better you make relations model/table with has and belongs to many

see here for more Save PHP array to MySQL?

here are the example that you can follow from railscasts

http://railscasts.com/episodes/17-habtm-checkboxes-revised

http://railscasts.com/episodes/196-nested-model-form-revised (about questions and answers too)

Community
  • 1
  • 1
buncis
  • 2,148
  • 1
  • 23
  • 25
  • My array is coming from a select field on a form with multiple: true Looking at those videos, they seem focused on the has and belongs to many aspect for the creation of the survey, not the response? – Will Ross May 23 '16 at 18:47