Mehdi Mehrtash


500 Experience
4 Lessons Completed
0 Questions Solved


I am using the Mailboxer gem. When creating a new conversation, the message that is created at that point is does not attach the file I am uploading.

= form_tag conversations_path, method: :post do
= select_tag :user_id, options_from_collection_for_select(@recipients, :id, :first_name)
= text_field_tag :subject, nil, placeholder: "Subject", class: "form-control"
= text_area_tag :body, nil, placeholder: "Leave a comment", class: "form-control"
= file_field_tag :attachment
= submit_tag "Send"

def create
recipient = User.find(params[:user_id])
receipt = current_user.send_message(recipient, params[:body], params[:subject], true, params[:attachment],
redirect_to conversation_path(receipt.conversation)


** params**
{"utf8"=>"✓", "authenticity_token"=>"R/wL/Zs4PTWJqHl5o3qHHnhhh2FewSymus3L0Svpdg0b9u1zcKTgnyGy4hJdGYhdNPU/hvL8Mq/dvNOUUCzXJg==", "user_id"=>"8", "subject"=>"Conversation Subject", "body"=>"Conversation Body", "attachment"=>"cupcake1.jpg", "commit"=>"Send", "controller"=>"conversations", "action"=>"create"}

** receipt.message**

According to the documentation, that is the order of the send_message method
** def send_message(recipients, msg_body, subject, sanitize_text=true, attachment=nil, message_timestamp =**

Thank you for your help

Posted in How do I add multiple attachments to Mailboxer?

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"?

= 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][]"
= f.submit "Send", class: "submit"

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)

Thank you very much!

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.