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.

2

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.