[英]Generate file and upload in back ruby on rails
I have the following code that generates an excel我有以下生成excel的代码
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet
.
.
.
send_data file_contents.string.force_encoding("binary"), filename: file_name
but I need to upload the file as an attachment to a comment without downloading it from the same back upload the file.但我需要将文件作为评论的附件上传,而不是从同一回上传文件下载。
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**)
please help me请帮我
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)
it worked for me它对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.