title: Ruby on Rails: passing in a variable to an active record query
body: <p>This question relates to a RoR quiz app.  I am looking to display the results of the quiz, showing both the correct answer as well as the user's answer.</p>
  
  <p>Therefore, in my view, I need to loop through each question and show the question answer, as well as the user's answer.  However, I am struggling trying to figure out how to correctly query the user's answer.</p>
  
  <p>To query the user_answer, I need the response_set where the user_id = current_user.id and I need to pass in the question_id as it loops through the each loop. However, I'm stuck on how to accomplish this.</p>
  
  <p>What do I need to do to show the user_answer in the view alongside the correct_answer?</p>
  
  <p><strong>I have 3 models:</strong></p>
  
  <pre><code>Response_set
  belongs_to :user
  has_many :responses
  
  Reponse
  belongs_to :response_set
  belongs_to :question
  
  Question
  has_many :responses
  </code></pre>
  
  <p><strong>Table fields:</strong></p>
  
  <pre><code>create_table :response_sets do |t|
    t.integer :user_id
  
  create_table :responses do |t|
    t.integer :response_set_id
    t.integer :question_id
    t.integer :user_answer
  
  create_table :questions do |t|
    t.integer :correct_answer
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@questions = Question.all
  @user = current_user.id
  </code></pre>
  
  <p><strong>View (just looping through the questions and not displaying the user's answer)</strong></p>
  
  <pre><code>&lt;% @questions.each do |question| %&gt;
     &lt;%= question.correct_answer %&gt;
  &lt;% end %&gt;
  </code></pre>