Wednesday 15 February 2012

.last and .each in rails -


I create a new sub-comment when trying to get the last record in a scene ... my code is The following ...

  & lt;% @ subcomment = @ comment.subcomments.order ("created_at"). Last% & gt; & Lt;% @ subcomment.each do | Comment | & Gt%; It worked! & Lt;% end% & gt;   

I know that the last record for the Subbuant is ... (i.e. when I use it. Insist, this shows the object), but for some reasons, .each gives the following error is .. .

I need to use it.

  Undefined method 'each' for noMethodError (# & lt; subcomment: 0x007fb14c0e5510 & gt;). See  

thanks for showing all sub-comments in general.

Finally ... I want something like this:

  <% if defined? Showlist% & 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 @ sagments & gt; & Gt; There is a long templates for what to do with   

i.e. I want the template to be repeated multiple times and should work for the last item if a parameter is sent to the showstol

Last usage will only bring you a choice, you can not run on the same thing again.

No comments:

Post a Comment