I am making a feature to allow user to attach multiple attachments while sending the email. I have added multiple:true and multipart:true but am not been able to attach multiple attachments. Please help me how can I do that. Also, please mention, how can I display the uploaded file names , 1 after another. Note: I am using paperclip
My code:
Form.html.erb
<%= form_tag mass_mail_reseller_path, :multipart => true, class: "new-mail-form form-horizontal" do%>
<div class="row form-group">
<div class="row form-group">
<%= label_tag "attachment", 'Attachment:', class: "col-sm-1 control-label"%>
<div class="col-sm-10">
<%= file_field_tag "attachment", multiple: true %>
</div>
</div>
<% end %>
my_controller.rb#action
def mail_reseller
_from = params[:from]
_to = get_resellers_mail_Ids(params[:to])
_subject = params[:subject]
_content = params[:body]
if params[:attachment]
_filename = params[:attachment].original_filename
_file = params[:attachment].read
end
Resque.enqueue(ResellerWorker, _to, _from, _subject, _content, _filename, _file)
flash[:notice] = "Mail has been sent."
redirect_to reseller_admin_path(:project_id => 'lead_tracking_reseller')
# directory = "#{Rails.root}/files"
# path = File.join(directory, _filename)
# File.open(path, "wb") { |f| f.write(params[:attachment].read) }
end
mailers/my_mailer.rb
def mass_mail_resellers _to, _from, _subject, _content, _filename, _file
attachments[_filename] = _file if (_filename && _file)
@mail_body = _content
mail from: _from,
to: _to,
bcc: 'jam@company.com',
subject: _subject
end
Aucun commentaire:
Enregistrer un commentaire