On my blog index pages (the blog page itself and the tag page), I’m seeing a literal array of the objects the template is supposed to be rendering at the bottom of the page, after the rendered HAML I’d expect.
I took a screenshot of the rendered index page for the blog.
In order to troubleshoot, I stuck in a comment in the HAML:
= partial("tag_list", :locals => {:article => article})
= article.summary
= link_to "Read More »", article
/looking for where in the render that weird thing is coming form
This screenshot seems to indicate the inserted junk appears before the comment in the rendered source.
I’ve pared back all the HAML and logic in the template to the bare minimum to get the page to render:
= blog.articles.each do |article|
= article.title
/looking for where in the render that weird thing is coming from - blog page
… and I still get the array.
I wrote this hoping that explaining my steps would help me figure it out, but whatever it is is so obvious that it’s eluding even that strategy. What am I missing or doing wrong here?
Solution
Rookie HAML mistake. There’s a syntax error with the top of the loop (using =
) that causes code to be evaluated and also inserted into the document. So the object is returned. Using -
keeps the result of the evaluation from being inserted.
Change:
=blog.articles.each
to
- blog.articles.each
and all is fine.