简体   繁体   English

如何实现邮件的多个附件? 在邮箱宝石中

[英]How to implement multiple attachments to messages? in mailboxer gem

I am using the Mailboxer gem . 我正在使用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? 创建一个名为message_attachment的新模型会是一个好主意吗? 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. 在这种情况下,如何设置消息模型(当前在我的模型文件夹中还没有),以便可以包含has_many :message_attachments请为我提供解决方案或示例代码。

I can show you path. 我可以告诉你道路。

First off, you need to fork the repository and make changes in Mailboxer::Message model for 首先,您需要派生存储库并在Mailboxer::Message模型中进行更改

  1. Remove existing mounted uploader which allows to upload a single attachment 删除允许上载单个附件的现有已挂载的上载器
  2. Define associations has_many :attachments 定义关联has_many :attachments
  3. Allows nested attributes using accepts_nested_attributes_for :attachments 允许使用accepts_nested_attributes_for :attachments嵌套属性accepts_nested_attributes_for :attachments

Then you can add Mailboxer::Attachment model and associate it with Mailboxer::Message using belogns_to :message 然后,您可以添加Mailboxer::Attachment模型,并使用belogns_to :message其与Mailboxer::Message关联

After that modify the relevant controller to permit attachments assuming your form is passing attributes following rails convention for nested attributes. 之后,修改相关的控制器以允许附件,假设您的表单按照嵌套属性的rails约定传递属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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