Forum: Ruby on Rails undefined local variable in partial

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Torsten S. (Guest)
on 2005-12-18 14:57
(Received via mailing list)
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:     <tr valign="top">
12:       <td>
13:         <div class="olnamebox"><%= h(order_line.name) %></div>
14:         <div class="oladdress"><%= h(order_line.address) %> </div>
15:       </td>


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
Spectre013 (Guest)
on 2005-12-22 05:45
(Received via mailing list)
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
Theron P. (Guest)
on 2006-10-17 06:56
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:
<tr valign="top">
<td>
<div class="olnamebox"><%= h(order_line.name) %></div>
<div class="oladdress"><%= h(order_line.address) %> </div>
</td>

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
Theron P. (Guest)
on 2006-10-17 07:34
I figured out the problem....it turns out that I had named a variable in
my order model <at>pending_order and named it <at>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.
This topic is locked and can not be replied to.