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!

Reply
Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.