A quiz game on ruby on rails [closed]

一曲冷凌霜 提交于 2019-12-06 12:20:31

问题


I am working on a quiz game using ruby on rails. I have created the basic authentication and other pages. Now I am starting work on creating the main game. I want to get an opinion about what method should I use i.e. create a seperate view for each question or is there a gem to do the same? Or some other method


回答1:


I would suggest to use a nested form with a partial as described in this RailsCast.




回答2:


Well the questions follow a pattern, don't they?

They have a question text and a certain number of answers. One of these answers is defined as 'correct'. Something like this could be appropriate:

(this is just an attribute representation of question and answer objects. use actual models and save the values to the database!)

# Question:
{ :question_id => 1,
  :text => 'What is StackOverflow?',
  :answers => # Answers:
                [{:answer_id => 1, :text => 'A search engine'},
                 {:answer_id => 2, :text => 'An info page for flood victims'},
                 {:answer_id => 3, :text => 'A website for asking coding related questions'} ],
  :correct_answer_id => 3 }

Now use a basic template to display the general question values and list all nested answer objects.

<p><%=h @question.text %></p>
<ol>
   <% @question.answers.each do |answer| %>
      <li><%=h answer.text %></li>
   <% end %>
</ol>

Extend this to an actual form to allow submitting of answers and you're set.




回答3:


Look at survey gem https://github.com/NUBIC/surveyor and blog post http://www.runtime-revolution.com/runtime/blog/introducing-survey#.Uut5jJBEyj4 .



来源:https://stackoverflow.com/questions/21458355/a-quiz-game-on-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!