# same html elements rendering twice on page

**URL:** <https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725>\
**Category:** rubyonrails-talk\
**Created:** [September 4, 2011, 9:38pm UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725 "2011-09-04T21:38:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Merlino](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@John\_Merlino](https://discuss.rubyonrails.org/u/John_Merlino)\
**Post date:** [September 4, 2011, 9:38pm UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725/1 "2011-09-04T21:38:59Z")

</div>

hey all,

My index.html.haml:

- wrap do &nbsp;&nbsp;- page\_title "Teams List View"

application\_helper.rb:

&nbsp;&nbsp;def page\_title(title) &nbsp;&nbsp;&nbsp;&nbsp;content\_tag :h1, title &nbsp;&nbsp;end

&nbsp;&nbsp;def wrap(&block) &nbsp;&nbsp;&nbsp;&nbsp;concat(content\_tag(:div, capture(&block), :class =\> "generic\_header")) &nbsp;&nbsp;end

I load in browser and get: \<div class="generic\_header"\>\<h1\>Teams List View\</h1\>\</div\> \<div class="generic\_header"\>\<h1\>Teams List View\</h1\>\</div\>

It's rendered twice. Not sure why. I invoke the wrap iterator, passing a block into the argument list, wrap receivers it as a reference, then I concat a div, use capture to render the page title as nested within div, and assign div class. Not sure what I am doing wrong.

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [September 5, 2011, 8:22am UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725/2 "2011-09-05T08:22:52Z")

</div>

What happens if you get rid of concat()?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [September 5, 2011, 12:19pm UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725/3 "2011-09-05T12:19:02Z")

</div>

By the way, if you put some html at the top of the page, e.g.

%p Index.html.haml - wrap do &nbsp;&nbsp;- page\_title "Teams List View"

Your wrap() method will double render the whole page.

Based on my experiments with haml, I would never consider using a multiline ruby block that contains a rails helper. The results are too unpredictable. Both of these syntaxes do what you want (without concat):

- wrap do &nbsp;&nbsp;- page\_title "Teams List View"

- wrap do &nbsp;&nbsp;= page\_title "Teams List View"

Note that in this code:

content\_tag(:div, capture(&block), :class =\>"generic\_header")

...capture() does indirectly what block.call() does directly.

---

<div class="post-metadata">

**Author:** ![John\_Merlino](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@John\_Merlino](https://discuss.rubyonrails.org/u/John_Merlino)\
**Post date:** [September 5, 2011, 12:28pm UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725/4 "2011-09-05T12:28:43Z")

</div>

thanks for response, and the explanation of capture(). When I removed the concat from the helper, the title stopped rendering twice. I thought the concat was used to concatenate the two blocks of html, but after reading documentation it appears it's to render haml without using "=".

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [September 5, 2011, 12:37pm UTC](https://discuss.rubyonrails.org/t/same-html-elements-rendering-twice-on-page/60725/5 "2011-09-05T12:37:41Z")

</div>

It seems to me that the = sign in haml is arbitrary and capricious. For instance, how does the syntax:

- wrap do &nbsp;&nbsp;- page\_title "Teams List View"

result in anything being added to the page?
