How to implement multiple attachments to messages? in mailboxer gem

255 Views Asked by At

I am using the Mailboxer gem.

What is the best way to set up my controller so it saves all the attachments? (loop through it?)

Would making a new model called message_attachment be a good idea? In that case, how do I set up the message model (which I currently don't have in my model folder) so I can include has_many :message_attachments please provide me a solution or a sample code thanks.

1

There are 1 best solutions below

2
Amit Patel On

I can show you path.

First off, you need to fork the repository and make changes in Mailboxer::Message model for

  1. Remove existing mounted uploader which allows to upload a single attachment
  2. Define associations has_many :attachments
  3. Allows nested attributes using accepts_nested_attributes_for :attachments

Then you can add Mailboxer::Attachment model and associate it with Mailboxer::Message using belogns_to :message

After that modify the relevant controller to permit attachments assuming your form is passing attributes following rails convention for nested attributes.