簡體   English   中英

生成文件並上傳到 ruby​​ on rails

[英]Generate file and upload in back ruby on rails

我有以下生成excel的代碼

book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet

.
.
.

send_data file_contents.string.force_encoding("binary"), filename: file_name

但我需要將文件作為評論的附件上傳,而不是從同一回上傳文件下載。

TaskComment.create(task_execution_id: params[:bank_reconciliation][:task_execution],
                   user_id: 3, activity_step: params[:bank_reconciliation][:activity_id], comment: "comenteario",
                   file1: **here file**)

請幫我

book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet sheet1.row(0).push "", "CHEQUES COBRADOS Y NO CONTABILIZADOS ", "$" temp_file = Tempfile.new(filename) book.write temp_file.path upload = ActionDispatch::Http::UploadedFile.new({ :filename => "conciliacion_bancaria.xls", #:type => "application/vnd.ms-excel", :type => "application/excel", :tempfile => temp_file, }) TaskComment.create( file1: upload)

它對我有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM