# Acess local variables from helper?

**URL:** <https://www.ruby-forum.com/t/acess-local-variables-from-helper/57717>\
**Category:** Rails\
**Created:** [April 13, 2006, 11:30am UTC](https://www.ruby-forum.com/t/acess-local-variables-from-helper/57717 "2006-04-13T11:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orotone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/90db22/32.png) [@orotone](https://www.ruby-forum.com/u/orotone)\
**Post date:** [April 13, 2006, 11:30am UTC](https://www.ruby-forum.com/t/acess-local-variables-from-helper/57717/1 "2006-04-13T11:30:42Z")

</div>

if I call a helper method from inside a partial, it doesn’t appear to  
have  
access to the partials local variables. is there a way to make them  
avilable  
without passing them as parameters?

here’s a simple example

# in the view

\<%= render :partial =\> “my\_partial”, :locals =\> :value =\> 2%\>

# \_my\_partial.rhtml - raises "undefined local variable or method

`value’"  
\<%= show\_value %\>

# helper method

def show\_value  
value  
end

---

<div class="post-metadata">

**Author:** ![orotone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/90db22/32.png) [@orotone](https://www.ruby-forum.com/u/orotone)\
**Post date:** [April 13, 2006, 11:40am UTC](https://www.ruby-forum.com/t/acess-local-variables-from-helper/57717/2 "2006-04-13T11:40:04Z")

</div>

My first thought is that you could make value an attribute (though that  
means they’re no longer local), so you’d have

# in the view

\<% @value = 2 %\>  
\<%= render :partial =\> “my\_partial” %\>

# \_my\_partial.rhtml - raises "undefined local variable or method

`value’"  
\<%= show\_value %\>

# helper method

def show\_value  
@value  
end

But to me it seems better to just pass your values in as parameters.

Daniel

---

<div class="post-metadata">

**Author:** ![orotone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/90db22/32.png) [@orotone](https://www.ruby-forum.com/u/orotone)\
**Post date:** [April 13, 2006, 11:58am UTC](https://www.ruby-forum.com/t/acess-local-variables-from-helper/57717/3 "2006-04-13T11:58:50Z")

</div>

“Daniel H.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> My first thought is that you could make value an attribute (though that  
> means they’re no longer local), so you’d have

I’m not sure if instance variables are practical in this case because  
the  
partial gets rendered many times (as a collection). Thanks for your  
suggestion though.
