0

I have a collection of Attachments, Notes, and Array of Attachments. For example

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

In my view I attempt to render this collection

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

but rails chokes saying the array of attachments needs to implement :to_partial_path

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

If I remove the array the rendering works great calling _attachment.html.erb and _note.html.erb for the respective records.

Is there a way to implement :to_partial_path on Array without monkey patching? Or is there another better solution?

1 Answer 1

1

You can create the class AttachmentArray, extend it from Array and add the to_partial_path method to it. Than push your attachments to a new instance of that class..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.