Re: Partial loop counter override by local variable

Cam
Wed, 06 Aug 2008 16:25:36 -0000

My bad, it does work.

<%= render(:partial => ''example'', :locals =>
{:example_counter => 5})
%>

Which is how you''d call it from an AJAX request, works.

I''ll look into whether there''s a test case.



On Aug 6, 5:14 pm, Cam <camerony...@gmail.com>
wrote:
> I''ve just tried the following on Edge;
>
> <%= render(:partial=> ''example'', :collection =>
%w(rails-doc is
> cool), :locals => {:example_counter => 5}) %>
>
> in the ''example''partial;
>
> Element: <%= example %> (index: <%= example_counter
%>)
>
> output;
>
> Element: rails-doc (index: 0)
> Element: is (index: 1)
> Element: cool (index: 2)
>
> so not only has the behaviour changed (counterstarting from 0, not
> 1), it''s still not allowing it to be overridden.
>
> How did you check it was working, Frederick?
>
> @Koz - I''ll try and write a patch/test which allows the
internalcounterto be overridden.
>
> On Aug 3, 11:44 pm, Frederick Cheung <frederick.che...@gmail.com>
> wrote:
>
> > On 3 Aug 2008, at 23:35, MarkMT wrote:
>
> > > Unfortunately, the ability to do this appears to have disappeared
in
> > > 2.1, and leaves me resorting to some pretty nasty stuff to
achieve the
> > > same effect. It appears that regardless of the value passed to
the
> > > local variable, when thepartialis invoked on an object,
internally
> > > the variable is just set to zero.
>
> > Looks like it''s back in edge :-)
> > Assuming it''s desirable behaviour, sounds to me like the
right thing
> > to do would be to add a test for it so that it doesn''t get
trampled on
> > in the future.
>
> > Fred
>
> > > This seems like a step backwards. Anyone want to explain the
thinking
> > > behind this, or suggest an elegant alternative strategy for
> > > implementing the kind of case I described?