[英]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
模型中进行更改
has_many :attachments
has_many :attachments
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.