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.
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.
On Wednesday, May 25, 2011 8:53:14 AM UTC-6, Ruby-Forum.com User wrote:
Welcome!
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.
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.
hmmm not really sure if I understand your question but here goes…
class AnswerController < ApplicationController
def index @questions = Question.find(:all)
end
end
If you have this code on your controller then the reason why it doesn’t
recognize your method is because @questions here is an Array of
Questions. So you have to loop through your array and display each
question.
So i think you have to do this on your index.html.erb
<% @questions.each do |q| %>
<%= q.question %>
<% end %>