views:

7

answers:

1

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:alt text

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}"}
+1  A: 

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 <%= ... %>). each method 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'

Nikita Rybak
well, i use haml. i edited my question to include the loop.
herpderp
@herpderp I don't use haml, but I suspect `=` sign there has the same meaning as in rails. Tried removing it? Also, [wikipedia article](http://en.wikipedia.org/wiki/Haml) features an 'each' example without it.
Nikita Rybak
= is necessary in haml, it denotes ruby code. without it haml treats the code as plain text. using - works too, but it doesn't solve my problem.
herpderp
OH WAIT, I had only changed = to - in the original loop in my index.html.haml file, not in the partial that contained the nested loops. everything's fine now, that solved it.
herpderp
@herpderp You can check [this section](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#ruby_evaluation) in haml docs about '=', '-' and similar stuff. And the whole documentation isn't that long, might be worth reading.
Nikita Rybak