# Helper content\_tag and Blocks

**URL:** <https://www.ruby-forum.com/t/helper-content-tag-and-blocks/88945>\
**Category:** Rails\
**Created:** [March 15, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/helper-content-tag-and-blocks/88945 "2007-03-15T19:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmckible](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@jmckible](https://www.ruby-forum.com/u/jmckible)\
**Post date:** [March 15, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/helper-content-tag-and-blocks/88945/1 "2007-03-15T19:46:25Z")

</div>

The content\_tag helper allows you to do things like:

content\_tag(:p, “Hello world!”)

# =\>

Hello world!

It can take in blocks, for functionality like this:

\<% content\_tag :div, :class =\> “strong” do -%\>  
Hello world!  
\<% end -%\>

# =\> Hello world!

Unfortunately blocks only work in erb and not as helper methods. This  
problem already has a ticket [http://dev.rubyonrails.org/ticket/7432](http://dev.rubyonrails.org/ticket/7432)

Greg Pierce has come up with a fix  
[http://greg.agiletortoise.com/2007/03/01/rails-content\_tag-block-fix](http://greg.agiletortoise.com/2007/03/01/rails-content_tag-block-fix) but  
I’m looking for more.

I’d like to write something along the lines of

content\_tag :table do  
content\_tag :tr do  
content\_tag :td, “first”  
content\_tag :td, “second”  
end  
end

With Greg’s fix, that code doesn’t crash at least, but the block.call  
line only returns the second td tag. I generally understand what the  
problem is, but my skills with Ruby blocks are coming up short. Anyone  
have an idea how to fix this?

---

<div class="post-metadata">

**Author:** ![jmckible](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c4cdca/32.png) [@jmckible](https://www.ruby-forum.com/u/jmckible)\
**Post date:** [March 17, 2007, 3:58am UTC](https://www.ruby-forum.com/t/helper-content-tag-and-blocks/88945/2 "2007-03-17T03:58:11Z")

</div>

If you want to write HTML like that, you should look at [Markaby](http://redhanded.hobix.com/inspect/markabyForRails.html).

greg.
