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

**URL:** <https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168>\
**Category:** Rails\
**Created:** [February 15, 2008, 1:45am UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168 "2008-02-15T01:45:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 15, 2008, 1:45am UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168/1 "2008-02-15T01:45:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 15, 2008, 1:49pm UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168/2 "2008-02-15T13:49:22Z")

</div>

On Thu, Feb 14, 2008 at 7:44 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 15, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168/3 "2008-02-15T17:14:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 15, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168/4 "2008-02-15T18:06:12Z")

</div>

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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 15, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/what-is-the-right-way-to-name-my-local-variable-in-my-partial/129168/5 "2008-02-15T18:55:01Z")

</div>

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