# Dynamic Survey System

**URL:** <https://www.ruby-forum.com/t/dynamic-survey-system/69369>\
**Category:** Rails\
**Created:** [September 20, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369 "2006-09-20T17:01:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/1 "2006-09-20T17:01:00Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/2 "2006-09-20T17:21:03Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/3 "2006-09-20T22:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/4 "2006-09-20T22:21:58Z")

</div>

> 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 🙂 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.

---

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/5 "2006-09-20T17:33:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![creativetags](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@creativetags](https://www.ruby-forum.com/u/creativetags)\
**Post date:** [September 20, 2006, 10:59pm UTC](https://www.ruby-forum.com/t/dynamic-survey-system/69369/6 "2006-09-20T22:59:23Z")

</div>

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.
