Creating a quiz-style demo app


#1

As an exercize to learn Ember, I’m trying to create a simple quiz app. A quiz has a list of questions that a user can view. Each question has a collection of possible answers. The user can select one answer for each question, which should create a Response record to track what answer the user selected for that particular question.

I understand most of what I’d need to do to get this working, but I’m a bit lost when it comes to the right way to store the Responses so that when I render a particular Question and its Answers for a User, I can highlight the Answer that corresponds to their Response for that Question, if one exists.

What’s the most Ember-like way for me to accomplish the sort of model structure and data-binding required so that clicking an Answer for a Question will create or update a Response record for the current User?

How do I initialize the data in the QuestionRoute so that when the Question template renders, the user’s selected Answer will render with a selected class? In Rails, I’d probably end up putting some simple logic in my view (template) to handle this, but I can’t have logic in a handlebars template (right?), so I’ll need to somehow represent this at an object collection level that the handlebars template renders against, right?

Example Models (the minimal fields needed to help communicate my question)

Quiz

  • id

Question

  • id
  • quiz_id

Answer

  • id
  • question_id
  • is_correct

User

  • id

Response

  • user_id
  • question_id
  • answer_id

#2

Can you share your code please ?