What is the right way to name my local variable in my partial?

Hi,

I have this invocation of a partial:

<%= render :partial => ‘summary_line_item’, @collection =>
@ec_order.ec_line_items %>

I thought just by naming the partial “summary_line_item”, each item
from the collection would be named “summary_line_item”. But I get
this error:

NoMethodError in Order#summary
Showing order/_summary_line_item.rhtml where line #12 raised:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.prescription_number

Here’s the code for the partial

=====================Begin _summary_line_item.rhtml

<%= summary_line_item.prescription_number %>
<%= summary_line_item.description %>
======================End _summary_line_item.rhtml =======================

Any idea how to properly name that loop variable in the partial? I
can name it anything other than “ec_line_item”, b/c I already have
another partial named “_ec_line_item.rhtml”. - Dave

On Thu, Feb 14, 2008 at 7:44 PM, [email protected]
[email protected] wrote:

       <!-- stuff -->

Perhaps it’s something in the above

       <div class="summaryField"><%=

summary_line_item.prescription_number %>

Any idea how to properly name that loop variable in the partial? I
can name it anything other than “ec_line_item”, b/c I already have
another partial named “_ec_line_item.rhtml”. - Dave

Having the other partial shouldn’t restrict you, we’re talking about
local variables here.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I guess I should take a step back. Given this from my summary.rhtml
file, how could I take the loop and convert it into a partial?

<% for summary_line_item in @ec_order.ec_line_items %>

Prescription ##
<%= image_tag '/images/RxICON_Cream.gif', options = {:alt => ""} %> Refill Number Description
<%= summary_line_item.prescription_number %> <%= summary_line_item.description %>
<% end %>

Thanks, - Dave

Ahh, I think I see your problem now:

<%= render :partial => ‘summary_line_item’, @collection =>
@ec_order.ec_line_items %>

should be:

<%= render :partial => ‘summary_line_item’, :collection =>
@ec_order.ec_line_items %>


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

As a commercial that I’ve seen would say … brilliant! Thanks, -