Forum: Ruby on Rails Collection of Partials, :as Option No Good, TemplateError

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.
5c262b1a445eb969fd2d411316f5365e?d=identicon&s=25 MaggotChild (Guest)
on 2009-02-24 20:14
(Received via mailing list)
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:
<tr>
  <td><%= package.upc %></td>
</tr>

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: <tr>
2:   <td><%= package.upc %></td>
3: </tr>
D93ae163042e0a937941e0ba4d8ed5d7?d=identicon&s=25 Eric (Guest)
on 2009-02-24 20:55
(Received via mailing list)
Why not use :locals => ?
5c262b1a445eb969fd2d411316f5365e?d=identicon&s=25 MaggotChild (Guest)
on 2009-02-24 22:55
(Received via mailing list)
On Feb 24, 11:54 am, Eric <ericgh...@gmail.com> wrote:
> On Feb 24, 11:13 am, MaggotChild <hsomob1...@yahoo.com> 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.
D93ae163042e0a937941e0ba4d8ed5d7?d=identicon&s=25 Eric (Guest)
on 2009-02-24 23:23
(Received via mailing list)
On Feb 24, 1:54 pm, MaggotChild <hsomob1...@yahoo.com> wrote:
> On Feb 24, 11:54 am, Eric <ericgh...@gmail.com> wrote:
>
> > On Feb 24, 11:13 am, MaggotChild <hsomob1...@yahoo.com> 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.
This topic is locked and can not be replied to.