# "locals" in render partial

**URL:** <https://www.ruby-forum.com/t/locals-in-render-partial/68159>\
**Category:** Rails\
**Created:** [September 9, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159 "2006-09-09T21:19:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 9, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/1 "2006-09-09T21:19:05Z")

</div>

Hi all,

I’m getting an error and I really don’t know why, because I seem to be  
doing everything well…I pass “testvar” as a variable to render partial:

\<%= render(:partial =\> “main/categorysmallitem”, :collection =\>  
group\_of\_four, :locals =\> {:testvar=\>“AA”})%\>

But then, when I try to use testvar inside the partial, it doesn’t  
recognize it:

\<%= testvar %\>

I get the error:  
undefined local variable or method `testvar’ for  
#\<#Class:0xb743eff4:0xb743efcc\>

Thanks a lot  
Victor

---

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 15, 2006, 5:15am UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/2 "2006-09-15T05:15:06Z")

</div>

I’m having the same problem! render :partial isn’t working as  
advertised in this case.

Would anybody have ideas? This is driving me nuts.

I’ll try the latest rails gem to see if that helps… I’ll post again if  
so… arrrrghh…  
– Dan

---

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 15, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/3 "2006-09-15T19:27:04Z")

</div>

I just tried v1.1.6, and no dice – I’m not seeing local variables in  
my partial templates.

HELP!

---

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 29, 2006, 10:19pm UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/4 "2006-09-29T22:19:40Z")

</div>

I am running a newer revision of edge and I am having this same problem.

---

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 29, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/5 "2006-09-29T22:29:41Z")

</div>

wait, nope…it does work. Looks like its fixed in the later edge, I  
am running 5196.

---

<div class="post-metadata">

**Author:** ![victor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@victor](https://www.ruby-forum.com/u/victor)\
**Post date:** [September 30, 2006, 12:50am UTC](https://www.ruby-forum.com/t/locals-in-render-partial/68159/6 "2006-09-30T00:50:50Z")

</div>

The problem in my case was purely ‘inattentiveness’: my partial was not  
called by  
the code passing the locals.  
I would try to debug your code flow to see if you really are calling the  
partial from where you think you are.

good luck  
Victor

Dan C. wrote:

> I just tried v1.1.6, and no dice – I’m not seeing local variables in  
> my partial templates.
> 
> HELP!
