How to implement multiple attachments using Ruby on Rails Action mailer -


i making feature allow user attach multiple attachments while sending email. have added multiple:true , multipart:true not been able attach multiple attachments. please me how can that. also, please mention, how can display uploaded file names , 1 after another. note: 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  model/resller.rb class reseller < user   has_many :settlements   belongs_to :account_manager, class_name: 'user', foreign_key: 'account_manager_id'   belongs_to :author, class_name: 'user', foreign_key: 'author_id'   has_and_belongs_to_many :plans   has_many :attachments end 

resellerworker code.

reseller_worker.rb

class resellerworker   @queue = :reseller_mail_queue   include redmine::i18n    def self.perform(_to, _from, _subject, _content, _filename, _file)     _to.each |_reseller|       resellermailer.mass_mail_resellers(_reseller, _from, _subject, _content, _filename, _file).deliver     end   end  end 


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -