---
title: Nesting content_tag in Rails 3
teaser:
tags: web,rails
author: Gabe Berke-Williams
published_on: 2011-08-19
---

Nesting `content_tag` in Rails 3 is counter-intuitive. This looks like it will work:

```ruby
content_tag(:ul) do
  collection.map do |item|
    content_tag(:li, item.title)
  end
end
```

But it doesn't. You get an empty list:

```html
<ul>
</ul>
```

What's the deal? To fix it, use the
[concat](http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-concat)
method:

```ruby
content_tag(:ul) do
  collection.map do |item|
    concat(content_tag(:li, item.title))
  end
end
```
