On Wednesday, May 25, 2011 8:53:14 AM UTC-6, Ruby-Forum.com User wrote:
>
> I'm sorry, I originally posted this topic on Rails-Deployment, but it's
> evidently the wrong area.
> I didn't want to, did that on distraction, sorry :)
>
> Anyway, the original post was this below:
>
> Hello!
> I'm at my very first application in Rails, and I'm learning from Agile
> Development with Rails.
>

Welcome! 

> I'm developing a web app that is run as a questionary.
> The idea is to create a database of questions (like 50), but use only
> like 10-15 each session, for each user.
> You can start the questionary only if you give your email
> address(validatates_presence_of).
>
> The point I'm wondering about is : since the answers are multiples and
> the sessions too, how can I keep track about whose belong certains
> answers? Shall I haven't a pool of mixed answers?
> I was thinking about a migration with 16 slots (email, and 15 slots for
> each answer), could that work? I know it's not exactly in the DRY logic,
> but in this way I'll have a complete table, with which I could also
> calculate how many correct answer the user did, and statistics stuff
> like that.
>
Have you considered a structure such as:

tables:
  questions (id, ...)
  answers (id, question_id, result_id, ...)
  results (id, email, ...)

With...

class Question < ActiveRecord::Base
  has_many :answers
end

class Answer < ActiveRecord::Base
  belongs_to :question
  belongs_to :result
end

class Result < ActiveRecord::Base
  has_many :answers
end

With this setup, you'd create a Result once a user gives you a valid email 
address (this could include checking if there is already a "result" from 
that email address). Then, your main questionnaire form loads a random set 
of Question instances (10-15) and, using them, renders your form(s) to ask 
them. As responses come in, you create/validate Answer instances that are 
linked to the current Result (represents the client's questionnaire session) 
and the proper Question.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to