Surveys, Questions and multiple choice answers

I have:

User, Survey, Question, Answer.

An admin would create a survey in a back-end system. They would name the survey, add many questions and add up to five multiple choice answer possibilities (along with point values for each of the individual answer choices.) This is for psychological assessments, so there isn’t a right answer, only a point value for selecting a specific answer. The creation of the survey part is finished and easy. The hard part is how users will answer.

For example:

Depression Survey

Q1: I feel upset when I watch sad movies

a) Never b) Always c) Sometimes d) Frequently e) Rarely

A user would select an answer, but I’m not sure what database field to use (or the format of the form) for which the response would be saved. I’m also not sure if I need another model (perhaps UserResponse which would belong to User and belong to Question.) Since there are n number of questions and y number of answer choices, the form is a bit confusing.

I was thinking that the form is something similar to this:

= form_for xxx do |f| #I don't know what should go into the xxx part
  - @survey.questions.each do |q|
    = q.content
    - q.answers.each do |q|
      = q.content

… but I don’t know where to go from there.

Finally, the point values from each answer will need to be summed at the end and stored.

Thanks! This is some basic Rails stuff, but it’s proving to be conceptually a bit difficult.

Hello @briandear,

The example app for Ruby Science has a similar use case, it might help to go throught the repo and the discussion for some features in the book.

Hope this helps :slight_smile:

1 Like