0

I'm in a tech summer camp and our teacher is showing us how to use Ruby on Rails. I told my teacher want I wanted to make and he told us to post here because it's important to learn from other developers.

I was looking on the site and found this question that is similar to what I want to do for my project. I want my friends to be able to read a few pages of text and then do a short test to make sure they were paying attention.

I want to make a hash table like the question I linked above but I don't know where to put it in my app! I would also like to tie it to users somehow so I can see which of my friends completed the test or not.

So far I have made user, question and answer models and would like to use a hash table like this test my fellow students.

# Question:
{ :question_id => 1,
  :text => 'What is Minecraft?',
  :answers => # Answers:
                [{:answer_id => 1, :text => 'A game'},
                 {:answer_id => 2, :text => 'A food'},
                 {:answer_id => 3, :text => 'A store'} ],
  :correct_answer_id => 1 }

Can someone tell me where I need to put this in my app and how I can save it to a database? My teacher said it is okay if people tell us how to do stuff as long as we tell him in our write up.

Community
  • 1
  • 1

1 Answers1

1

If you have related your answers with a has_many relationship to your question you can create answers with questions like this:

question = Question.create!(text => 'What is Minecraft?')
question.answer.create!(:text => 'A game')
question.answer.create!(:text => 'A food')
...

Ids will usually given out by the database, just don't need to define them yourself.

Axel Tetzlaff
  • 1,355
  • 8
  • 11