# Contet\_tag :ul question

**URL:** <https://www.ruby-forum.com/t/contet-tag-ul-question/187098>\
**Category:** Rails\
**Created:** [April 16, 2010, 9:26pm UTC](https://www.ruby-forum.com/t/contet-tag-ul-question/187098 "2010-04-16T21:26:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 16, 2010, 9:26pm UTC](https://www.ruby-forum.com/t/contet-tag-ul-question/187098/1 "2010-04-16T21:26:21Z")

</div>

Hi all

This isn’t doing what I expect it to. Can you give it a quick look-see  
if you have a moment?

def user\_navigation\_helper  
content\_tag(:div, :class =\>“banner\_right”) do  
content\_tag(:ul, :class =\> “wat-cf”) do  
if current\_user()  
content\_tag(:li) { current\_user.email }  
content\_tag(:li) { link\_to(“Edit profile”,  
edit\_user\_path(:current)) }  
content\_tag(:li) { link\_to(“Logout”, logout\_path) }  
else  
content\_tag(:li) { link\_to(“Login”, login\_path) }  
content\_tag(:li) { link\_to(“Register”, new\_user\_path) }  
end  
end  
end  
end

I am getting just one of the two or thee

- items. Is there a  
better/cleaner/correct way of doing this? Thanks!

Pito

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 17, 2010, 2:43am UTC](https://www.ruby-forum.com/t/contet-tag-ul-question/187098/2 "2010-04-17T02:43:40Z")

</div>

On Apr 16, 8:26 pm, Pito S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am getting just one of the two or thee
> 
> - items. Is there a  
> better/cleaner/correct way of doing this? Thanks!

When used in this context, content\_tag returns a string with  
corresponding fragment of html. Your innermost calls to content\_tag  
aren’t doing anything with that result whereas you probably want to be  
concatenating them.

Fred

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 17, 2010, 11:53pm UTC](https://www.ruby-forum.com/t/contet-tag-ul-question/187098/3 "2010-04-17T23:53:03Z")

</div>

On Fri, Apr 16, 2010 at 3:26 PM, Pito S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> content_tag(:li) { link_to("Edit profile",
> 
> ```
> 
> I am getting just one of the two or thee
> 
> - items. Is there a  
> better/cleaner/correct way of doing this? Thanks!

one way:

def user\_navigation\_helper  
content\_tag(:div, :class =\>“banner\_right”) do  
content\_tag(:ul, :class =\> “wat-cf”) do  
if current\_user()  
[content\_tag(:li) { current\_user.email },  
content\_tag(:li) { link\_to(“Edit profile”,  
edit\_user\_path(:current)) },  
content\_tag(:li) { link\_to(“Logout”, logout\_path) }]].join  
else  
[content\_tag(:li) { link\_to(“Login”, login\_path) },  
content\_tag(:li) { link\_to(“Register”, new\_user\_path) }].join  
end  
end  
end  
end

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 18, 2010, 12:08am UTC](https://www.ruby-forum.com/t/contet-tag-ul-question/187098/4 "2010-04-18T00:08:16Z")

</div>

Thanks both!! So the code snippet below now works correctly… Is there  
a more typical way of doing what I am doing or would you consider this  
idiomatic rails?

– PIto

def user\_navigation\_helper  
content\_tag(:div, :class =\>“banner\_right”) do  
content\_tag(:ul, :class =\> “wat-cf”) do  
if current\_user()  
content\_tag(:li) { current\_user.email } +  
content\_tag(:li) { link\_to(“Edit profile”,  
edit\_user\_path(:current)) } +  
content\_tag(:li) { link\_to(“Logout”, logout\_path) }  
else  
content\_tag(:li) { link\_to(“Login”, login\_path) } +  
content\_tag(:li) { link\_to(“Register”, new\_user\_path) }  
end  
end  
end  
end
