In my rails app I’m displaying some posts using nested loops. In development mode, after each loop completes the post objects are dumped in plain text in sequence. So it looks like this:
It’s unnecessary and kind of obnoxious. What causes this behavior and how do disable it? Edit: here is the loop:
= @posts.each do |post|
.post
%p= post.text
.replies
= if post.children != 0
= link_to "#{post.children} replies", '#',:toggled=>'no',:id=>"parent#{post.id}",:class=>"viewreplies",:rel=>post.children
%a.reply{:href => '#',:id => "reply#{post.id}",:rel => "thread#{post.thread}",:toggled=>'no' } Reply
%form{:method=>:post, :action => '/create', :class => 'replyform' }
= token_tag
%div{:id=>"replies#{post.id}"}
That’s not the case by default, you’re dumping Post objects in there explicitly in some place.
My guess is you have additional
=sign in<% @posts.each do |post| %>(i.e., you use<%= ... %>).eachmethod returns collection itself (for possible chaining, like in jquery) and there’s little point in printing it.If you have any confusion about the difference,
<% .. %>means ‘execute this’<%= .. %>means ‘execute this and print return value on the page’