# Why doesn't this helper work?

**URL:** <https://www.ruby-forum.com/t/why-doesnt-this-helper-work/189566>\
**Category:** Rails\
**Created:** [June 3, 2010, 9:25am UTC](https://www.ruby-forum.com/t/why-doesnt-this-helper-work/189566 "2010-06-03T09:25:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [June 3, 2010, 9:25am UTC](https://www.ruby-forum.com/t/why-doesnt-this-helper-work/189566/1 "2010-06-03T09:25:14Z")

</div>

So I’m cleaning up my views at the moment, and thought it’d be nice to  
create a couple of helpers, one that shows links if the user is logged  
in, and one that shows another set of links if they’re not logged in.

Anyways, this is the code:

def logged\_in\_links  
if logged\_in?  
link\_to ‘New Highlight’, new\_highlight\_path  
link\_to ‘Logout?’, logout\_path  
link\_to ‘Profile Â»’, @current\_user.login  
end  
end

I’m sure I’m making a rudimentary mistake (take into account I am a  
beginner), but whenever I execute the helper method only the last link  
shows up, and if I remove the last link than it’s the new last link that  
displays etc.

What am I doing wrong? 🙂

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [June 3, 2010, 9:30am UTC](https://www.ruby-forum.com/t/why-doesnt-this-helper-work/189566/2 "2010-06-03T09:30:17Z")

</div>

Hello, only results of the last statement executed are returned. You  
have to  
do something like

def logged\_in\_links  
html = ‘’  
if logged\_in?  
html += link\_to ‘New Highlight’, new\_highlight\_path  
html += link\_to ‘Logout?’, logout\_path  
html += link\_to ‘Profile Â»’, @current\_user.login  
end  
html  
end

2010/6/3 David T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [June 3, 2010, 9:38am UTC](https://www.ruby-forum.com/t/why-doesnt-this-helper-work/189566/3 "2010-06-03T09:38:51Z")

</div>

Ah, okay. Thanks for the hlep.

Gintautas Å imkus wrote:

> Hello, only results of the last statement executed are returned. You  
> have to  
> do something like
> 
> def logged\_in\_links  
> html = ‘’  
> if logged\_in?  
> html += link\_to ‘New Highlight’, new\_highlight\_path  
> html += link\_to ‘Logout?’, logout\_path  
> html += link\_to ‘Profile Â»’, @current\_user.login  
> end  
> html  
> end
> 
> 2010/6/3 David T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
