All threads / Mailboxer: How to attach a file when starting a new conversation

Ask A Question


You’re not receiving notifications from this thread.

Mailboxer: How to attach a file when starting a new conversation

Mehdi Mehrtash asked in Rails

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

Join the discussion

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

Join 52,887+ 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

    © 2021 GoRails, LLC. All rights reserved.