How to order a model by id in the view?
<p>I'm using heroku to run a quiz app.  </p>

<pre><code>class Question
  belongs_to :quiz
end

class Answer
  belongs_to :question
end
</code></pre>

<p>So I generate the quiz using something like this:</p>

<pre><code>&lt;%  @questions.each do |question| %&gt;

 // put questions here

  &lt;% question.answers.each do |answer| %&gt;

   // put answers here.

  &lt;% end #answer.each do %&gt;   

&lt;% end #questions.each do %&gt;
</code></pre>

<p>It's easy enough to order @questions. In my controller I have:</p>

<pre><code>@quiz = Quiz.find(params[:id])
@questions = @quiz.questions.order(:id)
</code></pre>

<p>so just using <code>order(:id)</code> I can ensure the questions are displaying in order of their id. I can't figure out a way to order answers the same way. </p>

<p><code>@answers = @questions.answers.order(:id)</code> doesn't work because I assume ruby doesn't know which question I'm using. I can't just use <code>has_many :answers, through: :questions</code> in my <code>Quiz</code> model because then for every question, all the answers will be displayed. I want to somehow sort the answers in my view by id, something like</p>

<p><code>question.answers.order(:id).each</code> but when I do this nothing happens (because maybe Array doesn't have the order method?) What should I do?</p>