# Using a link conditionally in the view

**URL:** <https://www.ruby-forum.com/t/using-a-link-conditionally-in-the-view/173268>\
**Category:** Rails\
**Created:** [August 6, 2009, 12:12am UTC](https://www.ruby-forum.com/t/using-a-link-conditionally-in-the-view/173268 "2009-08-06T00:12:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 6, 2009, 12:12am UTC](https://www.ruby-forum.com/t/using-a-link-conditionally-in-the-view/173268/1 "2009-08-06T00:12:06Z")

</div>

I want to render a different link\_to name and url path based on an  
objects “status” attribute in the index view. Would love to know how  
to get the logic out of the view, but barring that, when I use if/else  
statements in erb I can only render 4 different link options.  
Likewise, case/when is only allowing me to show 2 different results?  
Not sure what I am doing wrong (except I am sure I am putting way too  
much logic in the view).

Any help or guidelines would be much appreciated.

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 6, 2009, 1:32am UTC](https://www.ruby-forum.com/t/using-a-link-conditionally-in-the-view/173268/2 "2009-08-06T01:32:51Z")

</div>

one way:

link\_to(obj.status\_name, #{obj.status}\_path)

this would require any extra routes to be added, as well as a  
status\_name attribute/model to supply the text.

---

<div class="post-metadata">

**Author:** ![brad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@brad](https://www.ruby-forum.com/u/brad)\
**Post date:** [August 6, 2009, 1:44am UTC](https://www.ruby-forum.com/t/using-a-link-conditionally-in-the-view/173268/3 "2009-08-06T01:44:34Z")

</div>

Eric,  
THANK YOU! That will work. I will have to modify some routes, but  
this is so much cleaner than what I was trying to do. Thanks alot for  
a second set of eyes.

Brad
