# Using "if else" in a helper

**URL:** <https://www.ruby-forum.com/t/using-if-else-in-a-helper/155412>\
**Category:** Rails\
**Created:** [December 11, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/using-if-else-in-a-helper/155412 "2008-12-11T16:22:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![atmorell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@atmorell](https://www.ruby-forum.com/u/atmorell)\
**Post date:** [December 11, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/using-if-else-in-a-helper/155412/1 "2008-12-11T16:22:51Z")

</div>

Hello,

I am trying to move some logic from my views into a helper. If album  
with id 123 is found the view displays “found”. If I replace 123 with  
something that does not exists the page is just blank… Why don’t I  
get the “not found” message?

Any ideas?

#album view  
\<%= link\_to\_album rescue nil %\>

#album helper  
def link\_to\_album  
if Album.find(123)  
link\_to “found”, @album  
else  
link\_to “not found”, @album  
end  
end

Best regards.  
Asbjørn Morell.

---

<div class="post-metadata">

**Author:** ![atmorell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/50afbb/32.png) [@atmorell](https://www.ruby-forum.com/u/atmorell)\
**Post date:** [December 11, 2008, 4:34pm UTC](https://www.ruby-forum.com/t/using-if-else-in-a-helper/155412/2 "2008-12-11T16:34:04Z")

</div>

On Thu, Dec 11, 2008 at 4:22 PM, atmorell [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I am trying to move some logic from my views into a helper. If album  
> with id 123 is found the view displays “found”. If I replace 123 with  
> something that does not exists the page is just blank… Why don’t I  
> get the “not found” message?
> 
> Any ideas?

Fire up your console and see what happens when you try these:

Album.find(123)

Album.find\_by\_id(123)
