Dynamic Survey System

hi

i’m trying to create a web app in rails which would allow an
administrator to setup a custom survey and allow users to fill-in the
survey. Sounds simple enough but how do you create a datastore
(presumably in mySQL) when you don’t know the type of each question? So
you could have 3 multiple choice questions then 1 text box followed by
a date chooser.

My thoughts are:
a) use generic types - such as text or blob and limit the number of
questions
b) generate the answers table upon completion of the the survey
structure - this then can’t be edited (but unlikely to need editing
cause you can’t change a survey after it’s started anyway or you
wouldn’t have a complete set of results).

I hope this is a generic enough question that the discussion will be
relevant to more than myself :slight_smile:

b) generate the answers table upon completion of the the survey
structure - this then can’t be edited (but unlikely to need editing
cause you can’t change a survey after it’s started anyway or you
wouldn’t have a complete set of results).

Think of all the various types of questions you might have…

  • true/false
  • multiple choice (pick one)
  • multiple choice (pick any)
  • free form (ie. text)
  • rating (1-5, etc. which is really just multiple choice, I guess)

Then build a schema to hold all of those. Then build a schema to hold
the
concept of a survey, which would consist of the name of the survey,
who’s
running it, etc. along with “links” to each of the questions built and
what order to display them in. Also consider having “pages” within a
survey that the questions might belong to.

-philip

Philip, is your suggestion to create a single model that will
accommodate any of these response types, or to create a distinct model
for each response type? I am designing a similar system and am curious
about your thoughts.

Thanks.

Paul Davis

Philip H. wrote:

b) generate the answers table upon completion of the the survey
structure - this then can’t be edited (but unlikely to need editing
cause you can’t change a survey after it’s started anyway or you
wouldn’t have a complete set of results).

Think of all the various types of questions you might have…

  • true/false
  • multiple choice (pick one)
  • multiple choice (pick any)
  • free form (ie. text)
  • rating (1-5, etc. which is really just multiple choice, I guess)

Then build a schema to hold all of those. Then build a schema to hold
the
concept of a survey, which would consist of the name of the survey,
who’s
running it, etc. along with “links” to each of the questions built and
what order to display them in. Also consider having “pages” within a
survey that the questions might belong to.

-philip

Philip, is your suggestion to create a single model that will
accommodate any of these response types, or to create a distinct model
for each response type? I am designing a similar system and am curious
about your thoughts.

Honestly I hadn’t thought about it that far :slight_smile: THere are probably pros
and cons to each I suppose…

Some things could be made simpler if you could use STI I suppose…
certainly they could share the survey_id, page_num, etc… fields.

thanks - that was quick.

it’s funny just writing the question down helped point me in the right
direction.
Your solution seems to be what I suspected but you’ve elaborated and
made it much clearer - particularly hadn’t thought of pages, thanks.

creativetags wrote:

hi

i’m trying to create a web app in rails which would allow an
administrator to setup a custom survey and allow users to fill-in the
survey.

I did this a couple of years ago. My co-worker thought it was a little
over-engineered, but my model was something like the following. Handles
multiple choice (radio or checkbox), true/false (just one example of
multiple choice), fill-in-the-blank, multiple-row questions, etc.

Survey
title
description

surveySections

SurveySection

surveys
title
description
position

questions

Question

surveySection
questionText
position

questionRows
questionOptionSet

QuestionRow

question
rowText
position
isFillIn

QuestionOptionSet

questionOptions
minSelections
maxSelections

QuestionOption
optionText
integerValue (for data collection, such as averaging responses)
position

questionOptionSet

SurveyResponse

survey
questionRow

selectedQuestionOptions
fillInValue

Something like that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs