[英]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.