Using "if else" in a helper


#1

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.


#2

On Thu, Dec 11, 2008 at 4:22 PM, atmorell 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)