rails中通过actionmailer发送多个回形针附件的方法

Method to send multiple paperclip attachments through actionmailer in rails

所以我需要我的邮件程序发送用户在创建时上传到表单中的附件。我使用 cocoon 和 paperclip 在表单中附加了多个文件。

这是我的 object_controller:

class RfqsController < ApplicationController
...

  def create
    @object= Rfq.new(rfq_params)

    respond_to do |format|
      if @object.save
        Object_mailer.object_message(current_user, @object).deliver
        format.html { redirect_to @object, notice: 'object was successfully created.' }

        format.html { render :new }
      end
    end
  end

...

这将发送带有多个附件的电子邮件

class ObjectMailer < ApplicationMailer

  default from: "test@test.com"
  def placeholder_message(user, rfq)
    @user = user

    object.object_attachments.each do |attachment|
      attachments[attachment.attachment_file_file_name] = File.read(attachment.attachment_file.path)
    end

    mail to: user.email, subject: "test" 
  end

end