Data Structure
I am building a online form, with about 20 multiple choice checkboxes.
I can get the nested data with this command.
raise params.to_yaml
I need to store these data and call them again later. I want to sort out which use开发者_如何学JAVAr chose which specific checkbox, i.e. who chose checkbox no.2?
What's the best way to store these data in database?
The easiest way to run reports on your collected data is going to be storing it in a structured fashion.
Something along the lines of:
Question has_many Answers
Answer belongs to User
Creating Question, Answer and User models with corresponding tables.
The alternative would be to just brute force through the YAML data. It might work for smaller data sets, but it won't be pretty. You could fetch all of the responses, iterate through the responses to find and collate the results for specific questions. I think the structured approach, although a little more legwork initially, is going to be easier in the long run.
you may take a look at smerf for questionnaire building, if not too over-killed
精彩评论