Dominic Marks
2005-Feb-11 13:11 UTC
render_collection_of_partials vs. loop whats the difference ?
This is likely a problem with my interpretation of the documentation. I have two classes joined by a table with appropriate relationships between both. I currently have a single record in the join table to test things. If I use the following in the view (HTML excluded), I get one item returned and rendered: <% @foo.bars.each do |@bar| %> <%= @bar.data %> <% end %> I thought from the docs that this could be rewritten as <%= render_collection_of_partials "bar", @foo.bars %> With, <%= @bar.data %> in _bar.rhtml. With the former, I get the expect single record result. With the latter, I get a single iteration, but my @bar doesn''t have any data. Have I misunderstood the function of r_c_o_p ? Thanks, -- Dominic
Steve Kellock
2005-Feb-11 14:41 UTC
Re: render_collection_of_partials vs. loop whats the difference ?
Have you tried dropping the @ from <%= @bar.data %> in _bar.rhtml so it is just <%= bar.data %> ? I belive that the object passed into a partial is accessable by a variable equal to the file name minus the prefixed underscore. At least, thats what''s working for me. Steve On Fri, 11 Feb 2005 13:11:20 +0000, Dominic Marks <dom-gd+YDj74CzhZn1Ae+yzdHQ@public.gmane.org> wrote:> This is likely a problem with my interpretation of the documentation. > > I have two classes joined by a table with appropriate relationships between > both. I currently have a single record in the join table to test things. > > If I use the following in the view (HTML excluded), I get one item returned > and rendered: > > <% @foo.bars.each do |@bar| %> > <%= @bar.data %> > <% end %> > > I thought from the docs that this could be rewritten as > > <%= render_collection_of_partials "bar", @foo.bars %> > > With, <%= @bar.data %> in _bar.rhtml. > > With the former, I get the expect single record result. With the latter, I get > a single iteration, but my @bar doesn''t have any data. > > Have I misunderstood the function of r_c_o_p ? > > Thanks, > -- > Dominic > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Dominic Marks
2005-Feb-11 14:52 UTC
Re: render_collection_of_partials vs. loop whats the difference ?
On Friday 11 February 2005 14:41, Steve Kellock wrote:> Have you tried dropping the @ from <%= @bar.data %> in _bar.rhtml so > it is just <%= bar.data %> ?Thats it. Thanks Steve> I belive that the object passed into a partial is accessable by a > variable equal to the file name minus the prefixed underscore. At > least, thats what''s working for me. > > Steve >-- Dominic
Steve Kellock
2005-Feb-11 15:03 UTC
Re: render_collection_of_partials vs. loop whats the difference ?
No prob. Easy questions are my specialty. :) On Fri, 11 Feb 2005 14:52:24 +0000, Dominic Marks <dom-gd+YDj74CzhZn1Ae+yzdHQ@public.gmane.org> wrote:> On Friday 11 February 2005 14:41, Steve Kellock wrote: > > Have you tried dropping the @ from <%= @bar.data %> in _bar.rhtml so > > it is just <%= bar.data %> ? > > Thats it. > > Thanks Steve > > > I belive that the object passed into a partial is accessable by a > > variable equal to the file name minus the prefixed underscore. At > > least, thats what''s working for me. > > > > Steve > > > > -- > Dominic > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >