MaggotChild
2009-Feb-24 19:13 UTC
Collection of Partials, :as Option No Good, TemplateError
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> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why not use :locals => ? On Feb 24, 11:13 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> 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>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MaggotChild
2009-Feb-24 21:54 UTC
Re: Collection of Partials, :as Option No Good, TemplateError
On Feb 24, 11:54 am, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 24, 11:13 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 24, 1:54 pm, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> On Feb 24, 11:54 am, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Feb 24, 11:13 am, MaggotChild <hsomob1...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---