2013-07-25 14 views
0

我有一组附件,注释和附件数组。例如在包含阵列的导轨中呈现异构对象列表

@heteroCollection = [Attachment, Note, Note, [Attachment, Attachment, Attachment]] 

在我看来,我试图使这个集合

<%= render :partial => @heteroCollection %> 

但轨道呛说附件的阵列需要实现:to_partial_path

[Attachment, ..., Attachment] is not an ActiveModel-compatible object. It must implement :to_partial_path 

如果我删除阵列对于相应的记录,渲染效果很好,呼叫_attachment.html.erb_note.html.erb

有没有一种方法来实现:to_partial_path数组没有猴子修补?还是有另一个更好的解决方案?

回答

1

您可以创建类AttachmentArray,从Array扩展它并将to_partial_path方法添加到它。比把你的附件推到该类的新实例..

+0

好主意!我会给它一个镜头。 – grossadamm

+0

它的工作原理,谢谢...我会标记它回答,当它让我。 – grossadamm

+0

太棒了!没问题! –