Re: Partial loop counter override by local variable

Cam
Wed, 06 Aug 2008 16:14:34 -0000

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 (counter starting 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 internal
counter to 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?