# Collection of Partials, :as Option No Good, TemplateError

**URL:** <https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258>\
**Category:** Rails\
**Created:** [February 24, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258 "2009-02-24T20:14:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [February 24, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258/1 "2009-02-24T20:14:17Z")

</div>

I’m trying to render a collection of partials using :as. It raises an  
undefined local variable exception. Not sure why:

~/delivery-log/app/views/packages $ ls -1  
\_package.html.erb  
\_package\_list.html.erb  
index.html.erb

index.html.erb:  
\<%=  
render :partial=\>‘package\_list’, :collection=\>@packages, :as=\>:package  
%\>

\_package\_list.html.erb:

 \<%= package.upc %\>

Seems simple, but it only raises the aforementioned exception:

ActionView::TemplateError (undefined local variable or method  
`package’ for #ActionView::Base:0xb7589ac8) on line #2 of packages/  
\_package\_list.html.erb:  
1:

  
2: \<%= package.upc %\>  
3:

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [February 24, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258/2 "2009-02-24T20:55:30Z")

</div>

Why not use :locals =\> ?

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [February 24, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258/3 "2009-02-24T22:55:04Z")

</div>

On Feb 24, 11:54 am, Eric [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Feb 24, 11:13 am, MaggotChild [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m trying to render a collection of partials using :as. It raises an  
> > undefined local variable exception. Not sure why:  
> > Why not use :locals =\> ?

Sure there a workarounds, but they don’t explain why :as won’t work.

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [February 24, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/collection-of-partials-as-option-no-good-templateerror/161258/4 "2009-02-24T23:23:24Z")

</div>

On Feb 24, 1:54 pm, MaggotChild [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Feb 24, 11:54 am, Eric [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > On Feb 24, 11:13 am, MaggotChild [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > I’m trying to render a collection of partials using :as. It raises an  
> > > undefined local variable exception. Not sure why:  
> > > Why not use :locals =\> ?
> 
> Sure there a workarounds, but they don’t explain why :as won’t work.

You’re right, of course (except for locals being a workaround), and it  
seems like they should work the same or similar, but since :as is  
nearly impossible to Google for I recommend whatever workable method  
presents itself. That is, all other things being equal, whichever  
method is better documented is the stronger one. But that’s just me.
