I''m aware that the "_counter" variable that''s accessible when rendering partials with collections was modified in Rails 2.1 so that it starts from 1 instead of 0. However I''m wondering if I might have discovered another change related to this that I haven''t read about anywhere. In Rails 2.0, I could pass a variable called <partialname>_counter to a partial as a local variable and it would take on the value that was passed rather than one generated automatically. I''ve found this useful when invoking the partial from an rjs template in response to an ajax request, e.g. to add an extra row to a table after it has initially been displayed. This worked fine in Rails 2.0. For some reason in the application I''m currently developing in 2.1 it doesn''t seem to work. Is this a known change from 2.0, or am I maybe just doing something else wrong that''s preventing it from working (which is completely possible)? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2 Aug 2008, at 00:16, MarkMT wrote:> > I''m aware that the "_counter" variable that''s accessible when > rendering partials with collections was modified in Rails 2.1 so that > it starts from 1 instead of 0. However I''m wondering if I might have > discovered another change related to this that I haven''t read about > anywhere. >It was changed back on edge> In Rails 2.0, I could pass a variable called <partialname>_counter to > a partial as a local variable and it would take on the value that was > passed rather than one generated automatically. I''ve found this useful > when invoking the partial from an rjs template in response to an ajax > request, e.g. to add an extra row to a table after it has initially > been displayed. >This sounds like an implementation detail (eg what gets set first? the automatic value or the manually specificied one) There was quite a lot of refactoring so i wouldn''t be surprised if something ill-defined like this changed. Fred> This worked fine in Rails 2.0. For some reason in the application I''m > currently developing in 2.1 it doesn''t seem to work. Is this a known > change from 2.0, or am I maybe just doing something else wrong that''s > preventing it from working (which is completely possible)? > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks. This is kind of aggravating. The original behavior seemed pretty intuitive and enabled me to do exactly what I wanted to very easily. If I''m right in my understanding of what''s happening now, it''s forcing me into a pretty nasty workaround. It appears that it the partial is called with an object instead of a collection, the internal counter is just set to zero. I''d be interested to know if anyone else can confirm that this is what happens. Mark. On Aug 1, 6:21 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Aug 2008, at 00:16, MarkMT wrote: > > > > > I''m aware that the "_counter" variable that''s accessible when > > rendering partials with collections was modified in Rails 2.1 so that > > it starts from 1 instead of 0. However I''m wondering if I might have > > discovered another change related to this that I haven''t read about > > anywhere. > > It was changed back on edge > > > In Rails 2.0, I could pass a variable called <partialname>_counter to > > a partial as a local variable and it would take on the value that was > > passed rather than one generated automatically. I''ve found this useful > > when invoking the partial from an rjs template in response to an ajax > > request, e.g. to add an extra row to a table after it has initially > > been displayed. > > This sounds like an implementation detail (eg what gets set first? the > automatic value or the manually specificied one) There was quite a lot > of refactoring so i wouldn''t be surprised if something ill-defined > like this changed. > > Fred > > > This worked fine in Rails 2.0. For some reason in the application I''m > > currently developing in 2.1 it doesn''t seem to work. Is this a known > > change from 2.0, or am I maybe just doing something else wrong that''s > > preventing it from working (which is completely possible)?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just to clarify and confirm what I said before - if a partial is called with an object instead of a collection, the internal counter is set to zero - even if the invoking template passes in a local variable with the same name as the counter, ie <partialname>_counter. Unlike other local variables, this one has no effect.So you can no longer override the counter by passing a local variable. On Aug 1, 10:44 pm, MarkMT <mark.thom...-EkmVulN54Sk@public.gmane.org> wrote:> Thanks. This is kind of aggravating. The original behavior seemed > pretty intuitive and enabled me to do exactly what I wanted to very > easily. If I''m right in my understanding of what''s happening now, it''s > forcing me into a pretty nasty workaround. It appears that it the > partial is called with an object instead of a collection, the internal > counter is just set to zero. I''d be interested to know if anyone else > can confirm that this is what happens. > > Mark. > > On Aug 1, 6:21 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 2 Aug 2008, at 00:16, MarkMT wrote: > > > > I''m aware that the "_counter" variable that''s accessible when > > > rendering partials with collections was modified in Rails 2.1 so that > > > it starts from 1 instead of 0. However I''m wondering if I might have > > > discovered another change related to this that I haven''t read about > > > anywhere. > > > It was changed back on edge > > > > In Rails 2.0, I could pass a variable called <partialname>_counter to > > > a partial as a local variable and it would take on the value that was > > > passed rather than one generated automatically. I''ve found this useful > > > when invoking the partial from an rjs template in response to an ajax > > > request, e.g. to add an extra row to a table after it has initially > > > been displayed. > > > This sounds like an implementation detail (eg what gets set first? the > > automatic value or the manually specificied one) There was quite a lot > > of refactoring so i wouldn''t be surprised if something ill-defined > > like this changed. > > > Fred > > > > This worked fine in Rails 2.0. For some reason in the application I''m > > > currently developing in 2.1 it doesn''t seem to work. Is this a known > > > change from 2.0, or am I maybe just doing something else wrong that''s > > > preventing it from working (which is completely possible)?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---