title: .last and .each in rails
body: <p>I'm trying to get the last record in a view when a new sub comment is created...my code is the following...</p>
  
  <pre><code>&lt;% @subcomment = @comment.subcomments.order("created_at").last %&gt;
  &lt;% @subcomment.each do |comment| %&gt;
      this worked!
  &lt;% end %&gt;
  </code></pre>
  
  <p>I know that @subcomment has the last record...(i.e. when i use .inspect, it shows the object), but for some reason using .each gives the following error...</p>
  
  <pre><code>NoMethodError (undefined method `each' for #&lt;Subcomment:0x007fb14c0e5510&gt;):
  </code></pre>
  
  <p>I need to use .each, since I use this view to show all sub comments in general.  How come .each won't work and what are the alternatives?</p>
  
  <p>Thank you.</p>
  
  <p>In the end...I want something like this:</p>
  
  <pre><code>&lt;% if defined? showlast %&gt;
      &lt;% @subcomments = @comment.subcomments.order("created_at").last %&gt;
      &lt;% [@subcomments].each do |subcomment| %&gt;
      &lt;div id="subcomments"&gt;
  &lt;% else %&gt;
  &lt;div id="subcomments"&gt;
    &lt;% @subcomments.each do |subcomment| %&gt;
       &lt;&lt;here is a long template of what to do with @subcomments&gt;&gt;
  </code></pre>
  
  <p>i.e. I want the template to iterate if multiple and work for the last item if a parameter :showlast is sent</p>