Jacek Becela
2007-Nov-12 12:14 UTC
ActionView::Partials doesn''t recognize not-yet-loaded HasManyThroughAssociationCollection
Hello,
In User model:
has_many :projects, :through => :authorizations
In view:
render :partial => @user.projects
This blows up because HasManyThroughAssociation inherits from
AssociationProxy and not AssociationCollection.
Partial logic checks if @user.projects === AssociationCollection which
returns false.
Quick workaround is: render :partial => @user.projects.to_a
(actionpack/lib/action_view/partials.rb rev8129 line 122):
def render_partial(partial_path, object_assigns = nil, local_assigns
= nil) #:nodoc:
case partial_path
...
when Array, ActiveRecord::Associations::AssociationCollection
...
Should it be changed to "when Array,
ActiveRecord::Associations::AssociationProxy" or
HasManyThroughAssociation should inherit from AssociationCollection?
--
Jacek
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Tarmo Tänav
2007-Nov-12 12:35 UTC
Re: ActionView::Partials doesn''t recognize not-yet-loaded HasManyThroughAssociationCollection
Isn''t this http://dev.rubyonrails.org/ticket/9051 ? On E, 2007-11-12 at 12:14 +0000, Jacek Becela wrote:> Hello, > > In User model: > has_many :projects, :through => :authorizations > > In view: > render :partial => @user.projects > > This blows up because HasManyThroughAssociation inherits from > AssociationProxy and not AssociationCollection. > > Partial logic checks if @user.projects === AssociationCollection which > returns false. > > Quick workaround is: render :partial => @user.projects.to_a > > (actionpack/lib/action_view/partials.rb rev8129 line 122): > > def render_partial(partial_path, object_assigns = nil, local_assigns > = nil) #:nodoc: > case partial_path > ... > when Array, ActiveRecord::Associations::AssociationCollection > ... > > Should it be changed to "when Array, > ActiveRecord::Associations::AssociationProxy" or > HasManyThroughAssociation should inherit from AssociationCollection? > > -- > Jacek > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jacek Becela
2007-Nov-12 13:04 UTC
Re: ActionView::Partials doesn''t recognize not-yet-loaded HasManyThroughAssociationCollection
Yup, somehow didn''t stumble upon that. On 12 Lis, 13:35, Tarmo Tänav <ta...@itech.ee> wrote:> Isn''t thishttp://dev.rubyonrails.org/ticket/9051? > > On E, 2007-11-12 at 12:14 +0000, Jacek Becela wrote: > > > Hello, > > > In User model: > > has_many :projects, :through => :authorizations > > > In view: > > render :partial => @user.projects > > > This blows up because HasManyThroughAssociation inherits from > > AssociationProxy and not AssociationCollection. > > > Partial logic checks if @user.projects === AssociationCollection which > > returns false. > > > Quick workaround is: render :partial => @user.projects.to_a > > > (actionpack/lib/action_view/partials.rb rev8129 line 122): > > > def render_partial(partial_path, object_assigns = nil, local_assigns > > = nil) #:nodoc: > > case partial_path > > ... > > when Array, ActiveRecord::Associations::AssociationCollection > > ... > > > Should it be changed to "when Array, > > ActiveRecord::Associations::AssociationProxy" or > > HasManyThroughAssociation should inherit from AssociationCollection? > > > -- > > Jacek--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---