简体   繁体   中英

How to implement multiple attachments to messages? in mailboxer gem

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM