# Problem with render in helper methods

**URL:** <https://www.ruby-forum.com/t/problem-with-render-in-helper-methods/184298>\
**Category:** Rails\
**Created:** [February 28, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/problem-with-render-in-helper-methods/184298 "2010-02-28T15:05:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [February 28, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/problem-with-render-in-helper-methods/184298/1 "2010-02-28T15:05:10Z")

</div>

I have a helper that renders a partial. The partial may or may not  
exist. If it does not exist then a different partial is rendered  
instead. Like this:

def render\_my\_partial my\_partial  
begin  
render :partial =\> “folder1/#{my\_partial}”  
rescue  
render :partial =\> “folder2/#{my\_partial}”  
end  
end

This in itself works fine. One of my layouts uses this helper to display  
one of two partials:

\<%=render\_my\_partial ‘display\_area’%\>

If one of these partials uses another helper that itself uses the above  
helper to render one of two other partials:

def info\_panel  
render\_my\_partial ‘info\_panel’  
end

This fails.

However, if I replicate the above code directly in the second helper  
function then it works.

def info\_panel  
begin  
render :partial =\> “folder1/info\_panel”  
rescue  
render :partial =\> “folder2/info\_panel”  
end  
end

I don’t understand this. I could leave it with duplicated code but it  
isn’t very DRY and I’d like to understand why this does not work as I  
expect. Can anyone help explain this to me?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [February 28, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/problem-with-render-in-helper-methods/184298/2 "2010-02-28T19:02:56Z")

</div>

Ignore this. Blonde moment 🙂
