This code does not work the same way as it did in 2.x: render :partial => "things", :object => [''foo'', ''bar'', ''baz''] In 2.x, the "things" partial would be rendered once with a local variable called "things" storing the given array. In 3.0.0 (and edge), the Action View assumes that you really meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the array and renders the partial once with each element. It will do this for any object which responds to to_ary. I really think this is a case of Rails being too clever for its own good. The difference in behaviour between the :object and :collection options is large enough that this makes for a big break in expectations. If someone wants the :collection behaviour, they should use :collection. (FWIW, an easy workaround is to pass the array into :locals, which people should probably be doing for arrays 99% of the time anyway, but silently assuming they meant :collection is not the way to encourage that behaviour.) The relevant change to the code is more than a year old now (commit d0301e1) but I couldn''t find any discussion about the change and the tests don''t seem to assert anything about it either way. If it''s really the behaviour we want, then it should be tested and documented. I can make a patch in either case. -James -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Prem Sichanugrist
2010-Sep-30 18:30 UTC
Re: rendering a partial with an array as its :object
This is interesting. I don''t think Rails should acts that way. It should only iterate through the collection only if :collection => is provided. Can you open the lighthouse ticket for this one? Thanks, Prem On 1 ต.ค. 2553, at 1:28, James MacAulay wrote:> This code does not work the same way as it did in 2.x: > > render :partial => "things", :object => [''foo'', ''bar'', ''baz''] > > In 2.x, the "things" partial would be rendered once with a local > variable called "things" storing the given array. > > In 3.0.0 (and edge), the Action View assumes that you really > meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the > array and renders the partial once with each element. It will do this > for any object which responds to to_ary. > > I really think this is a case of Rails being too clever for its own > good. The difference in behaviour between the :object and :collection > options is large enough that this makes for a big break in > expectations. If someone wants the :collection behaviour, they should > use :collection. > > (FWIW, an easy workaround is to pass the array into :locals, which > people should probably be doing for arrays 99% of the time anyway, but > silently assuming they meant :collection is not the way to encourage > that behaviour.) > > The relevant change to the code is more than a year old now (commit > d0301e1) but I couldn''t find any discussion about the change and the > tests don''t seem to assert anything about it either way. If it''s > really the behaviour we want, then it should be tested and documented. > I can make a patch in either case. > > -James > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Made a ticket: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5746-rendering-a-partial-with-an-array-as-its-object-behaves-as-if-it-were-collection -James On Sep 30, 2:30 pm, Prem Sichanugrist <sikand...@gmail.com> wrote:> This is interesting. I don''t think Rails should acts that way. It should only iterate through the collection only if :collection => is provided. > > Can you open the lighthouse ticket for this one? > > Thanks, > > Prem > > On 1 ต.ค. 2553, at 1:28, James MacAulay wrote: > > > > > > > > > This code does not work the same way as it did in 2.x: > > > render :partial => "things", :object => [''foo'', ''bar'', ''baz''] > > > In 2.x, the "things" partial would be rendered once with a local > > variable called "things" storing the given array. > > > In 3.0.0 (and edge), the Action View assumes that you really > > meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the > > array and renders the partial once with each element. It will do this > > for any object which responds to to_ary. > > > I really think this is a case of Rails being too clever for its own > > good. The difference in behaviour between the :object and :collection > > options is large enough that this makes for a big break in > > expectations. If someone wants the :collection behaviour, they should > > use :collection. > > > (FWIW, an easy workaround is to pass the array into :locals, which > > people should probably be doing for arrays 99% of the time anyway, but > > silently assuming they meant :collection is not the way to encourage > > that behaviour.) > > > The relevant change to the code is more than a year old now (commit > > d0301e1) but I couldn''t find any discussion about the change and the > > tests don''t seem to assert anything about it either way. If it''s > > really the behaviour we want, then it should be tested and documented. > > I can make a patch in either case. > > > -James > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Just wanted to point out that I made a patch for this, attached to the ticket, so any codereviews/feedback/+1''s would be great: https://rails.lighthouseapp.com/projects/8994/tickets/5746 -James On Sep 30, 2:43 pm, James MacAulay <jmacau...@gmail.com> wrote:> Made a ticket: > > https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5... > > -James >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Eugene M. Magdel
2010-Oct-23 21:05 UTC
Re: rendering a partial with an array as its :object
Had the same problem! Thanks for reporting! On Sep 30, 1:28 pm, James MacAulay <jmacau...@gmail.com> wrote:> This code does not work the same way as it did in 2.x: > > render :partial => "things", :object => [''foo'', ''bar'', ''baz''] > > In 2.x, the "things" partial would be rendered once with a local > variable called "things" storing the given array. > > In 3.0.0 (and edge), the Action View assumes that you really > meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the > array and renders the partial once with each element. It will do this > for any object which responds to to_ary. > > I really think this is a case of Rails being too clever for its own > good. The difference in behaviour between the :object and :collection > options is large enough that this makes for a big break in > expectations. If someone wants the :collection behaviour, they should > use :collection. > > (FWIW, an easy workaround is to pass the array into :locals, which > people should probably be doing for arrays 99% of the time anyway, but > silently assuming they meant :collection is not the way to encourage > that behaviour.) > > The relevant change to the code is more than a year old now (commit > d0301e1) but I couldn''t find any discussion about the change and the > tests don''t seem to assert anything about it either way. If it''s > really the behaviour we want, then it should be tested and documented. > I can make a patch in either case. > > -James-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Antonio Tapiador del Dujo
2010-Oct-28 14:08 UTC
Re: Re: rendering a partial with an array as its :object
I suffered this. I was very annoyed because Rails was rendering nothing. Then I realized I was passing an empty array and I remembered this issue! +1 El Sábado, 23 de Octubre de 2010 23:05:06 Eugene M. Magdel escribió:> Had the same problem! Thanks for reporting! > > On Sep 30, 1:28 pm, James MacAulay <jmacau...@gmail.com> wrote: > > This code does not work the same way as it did in 2.x: > > > > render :partial => "things", :object => [''foo'', ''bar'', ''baz''] > > > > In 2.x, the "things" partial would be rendered once with a local > > variable called "things" storing the given array. > > > > In 3.0.0 (and edge), the Action View assumes that you really > > meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the > > array and renders the partial once with each element. It will do this > > for any object which responds to to_ary. > > > > I really think this is a case of Rails being too clever for its own > > good. The difference in behaviour between the :object and :collection > > options is large enough that this makes for a big break in > > expectations. If someone wants the :collection behaviour, they should > > use :collection. > > > > (FWIW, an easy workaround is to pass the array into :locals, which > > people should probably be doing for arrays 99% of the time anyway, but > > silently assuming they meant :collection is not the way to encourage > > that behaviour.) > > > > The relevant change to the code is more than a year old now (commit > > d0301e1) but I couldn''t find any discussion about the change and the > > tests don''t seem to assert anything about it either way. If it''s > > really the behaviour we want, then it should be tested and documented. > > I can make a patch in either case. > > > > -James-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Prem Sichanugrist
2010-Oct-28 14:30 UTC
Re: Re: rendering a partial with an array as its :object
Can you create a ticket and assign to me. I''ll have a look on it. Thank you :) On 28 ต.ค. 2553, at 21:08, Antonio Tapiador del Dujo wrote:> I suffered this. I was very annoyed because Rails was rendering nothing. Then I > realized I was passing an empty array and I remembered this issue! > > +1 > > El Sábado, 23 de Octubre de 2010 23:05:06 Eugene M. Magdel escribió: >> Had the same problem! Thanks for reporting! >> >> On Sep 30, 1:28 pm, James MacAulay <jmacau...@gmail.com> wrote: >>> This code does not work the same way as it did in 2.x: >>> >>> render :partial => "things", :object => [''foo'', ''bar'', ''baz''] >>> >>> In 2.x, the "things" partial would be rendered once with a local >>> variable called "things" storing the given array. >>> >>> In 3.0.0 (and edge), the Action View assumes that you really >>> meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the >>> array and renders the partial once with each element. It will do this >>> for any object which responds to to_ary. >>> >>> I really think this is a case of Rails being too clever for its own >>> good. The difference in behaviour between the :object and :collection >>> options is large enough that this makes for a big break in >>> expectations. If someone wants the :collection behaviour, they should >>> use :collection. >>> >>> (FWIW, an easy workaround is to pass the array into :locals, which >>> people should probably be doing for arrays 99% of the time anyway, but >>> silently assuming they meant :collection is not the way to encourage >>> that behaviour.) >>> >>> The relevant change to the code is more than a year old now (commit >>> d0301e1) but I couldn''t find any discussion about the change and the >>> tests don''t seem to assert anything about it either way. If it''s >>> really the behaviour we want, then it should be tested and documented. >>> I can make a patch in either case. >>> >>> -James > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Antonio Tapiador del Dujo
2010-Oct-29 07:24 UTC
Re: Re: rendering a partial with an array as its :object
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5884- rendering-a-partial-with-an-array-as-its-object-should-not-render-as- collection El Jueves, 28 de Octubre de 2010 16:30:58 Prem Sichanugrist escribió:> Can you create a ticket and assign to me. I''ll have a look on it. > > Thank you :) > > On 28 ต.ค. 2553, at 21:08, Antonio Tapiador del Dujo wrote: > > I suffered this. I was very annoyed because Rails was rendering nothing. > > Then I realized I was passing an empty array and I remembered this > > issue! > > > > +1 > > > > El Sábado, 23 de Octubre de 2010 23:05:06 Eugene M. Magdel escribió: > >> Had the same problem! Thanks for reporting! > >> > >> On Sep 30, 1:28 pm, James MacAulay <jmacau...@gmail.com> wrote: > >>> This code does not work the same way as it did in 2.x: > >>> > >>> render :partial => "things", :object => [''foo'', ''bar'', ''baz''] > >>> > >>> In 2.x, the "things" partial would be rendered once with a local > >>> variable called "things" storing the given array. > >>> > >>> In 3.0.0 (and edge), the Action View assumes that you really > >>> meant :collection => [''foo'', ''bar'', ''baz''], so it iterates through the > >>> array and renders the partial once with each element. It will do this > >>> for any object which responds to to_ary. > >>> > >>> I really think this is a case of Rails being too clever for its own > >>> good. The difference in behaviour between the :object and :collection > >>> options is large enough that this makes for a big break in > >>> expectations. If someone wants the :collection behaviour, they should > >>> use :collection. > >>> > >>> (FWIW, an easy workaround is to pass the array into :locals, which > >>> people should probably be doing for arrays 99% of the time anyway, but > >>> silently assuming they meant :collection is not the way to encourage > >>> that behaviour.) > >>> > >>> The relevant change to the code is more than a year old now (commit > >>> d0301e1) but I couldn''t find any discussion about the change and the > >>> tests don''t seem to assert anything about it either way. If it''s > >>> really the behaviour we want, then it should be tested and documented. > >>> I can make a patch in either case. > >>> > >>> -James-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.