All threads / How do I add multiple attachments to Mailboxer?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I add multiple attachments to Mailboxer?

Mehdi Mehrtash asked in Rails

I am using the Mailboxer gem. I have enabled multiple file uploads for the attachment field. What is the best way to set up my controller so it saves all the attachments? 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"?

show.html.haml
= form_for @message, url: conversation_messages_path(@conversation) do |f|
= f.text_area :body, class: "form-control"
-# = f.file_field :attachment
= f.file_field :attachment, multiple: :true, name: "message_attachments[photo][]"
.yellow-btn
= f.submit "Send", class: "submit"

messages_controller.rb
def create
receipt = current_user.reply_to_conversation(@conversation, params[:mailboxer_message][:body], nil, true, true, params[:mailboxer_message][:attachment])
redirect_to conversation_path(@conversation)
end

Thank you very much!

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 35,699+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.