# Undefined local variable in partial

**URL:** <https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579>\
**Category:** Rails\
**Created:** [December 18, 2005, 1:57pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579 "2005-12-18T13:57:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![torstello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@torstello](https://www.ruby-forum.com/u/torstello)\
**Post date:** [December 18, 2005, 1:57pm UTC](https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579/1 "2005-12-18T13:57:43Z")

</div>

i can’t get rid of the following error:

ActionView::TemplateError (undefined local variable or method  
`order\_line’  
for #\<#Class:0xb75b2090:0xb75b1f28\>) on line #13 of  
app/views/admin/\_order\_line.rhtml:  
10:  
11:

  
12:   
13: 
\<%= h(order\_line.name) %\>
  
14: 
\<%= h(order\_line.address) %\> 
  
15: 

The partial is called from within a view (ship.rhtml):

\<%= render(:partial =\> “order\_line”, :collection =\> @pending\_orders)  
%\>

The PragProg-Rails book explains the following:

‘‘The order\_line parameter also tells Rails to set a local variable  
called  
order\_line to the value of the order currently being rendered. This  
variable  
is available only inside the partial template.’’

So why do i get the error above??

By the way: is it right that i get a blank page or should i see an  
error-page from rails?  
scrolling down my development.log is see the following:

ActionView::ActionViewError (No rhtml, rxml, or delegate template found  
for  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2  
/lib/action\_controller/templates/rescues/template\_error.rhtml):  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_view/base.rb:281:in  
`pick\_template\_extension’

Any hints?

Regards,  
Torsten

---

<div class="post-metadata">

**Author:** ![torstello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@torstello](https://www.ruby-forum.com/u/torstello)\
**Post date:** [December 22, 2005, 4:45am UTC](https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579/2 "2005-12-22T04:45:47Z")

</div>

having trouble with that page as well but I am getting this error

You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.name

Not sure why your getting that error that is strange.

Brian

---

<div class="post-metadata">

**Author:** ![torstello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@torstello](https://www.ruby-forum.com/u/torstello)\
**Post date:** [October 17, 2006, 4:56am UTC](https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579/3 "2006-10-17T04:56:01Z")

</div>

Spectre013 wrote:

> having trouble with that page as well but I am getting this error
> 
> You have a nil object when you didn’t expect it!  
> The error occured while evaluating nil.name
> 
> Not sure why your getting that error that is strange.
> 
> Brian

Does anyone know what the fix for this is? I’m following along with the  
first addition of agile web development with rails and it’s been going  
great until I got to page 118 and ran into the exact problem described  
above.

\_order\_line.rhtml:

\<%= h(order\_line.name) %\>

\<%= h(order\_line.address) %\> 

ship.rhtml  
\<%= render(:partial =\> “order\_line”, :collection =\> @pending\_orders)  
%\>

The error is:  
You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.name

Any help would much appreciated.

-Theron

---

<div class="post-metadata">

**Author:** ![torstello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3ec8ea/32.png) [@torstello](https://www.ruby-forum.com/u/torstello)\
**Post date:** [October 17, 2006, 5:34am UTC](https://www.ruby-forum.com/t/undefined-local-variable-in-partial/50579/4 "2006-10-17T05:34:33Z")

</div>

I figured out the problem…it turns out that I had named a variable in  
my order model pending\_order and named it pending\_orders in my  
admin\_controller so it wasn’t sending anything to my partial. That was a  
fun two hours that I’ll never get back. 🙂

Game on.
