Zip Excel sheet generated through gem axlsx rails -


i'm facing issue of how zip excel sheet generated through gem 'axlsx_rails'. example:

class samplecontroller < applicationcontroller::base    def export     if params[:zip]         xxxx     else       render xlsx: 'export', filename: filename, disposition: 'attachment'     end   end  end 

in above example, right end user able download excel sheet if end user requests zip file of excel sheet, how can that. because of code in 'else' block end user able download excel sheet. have if user wants excelsheet zipped before download. if need further info, plz let me know. thanks

this untested code, try using zip::zipoutputstream:

def export   if params[:zip]     compressed_filestream = zip::zipoutputstream.write_buffer |zos|       content = render_to_string xlsx: 'export', filename: filename       zos.put_next_entry(filename)       zos.print content     end     compressed_filestream.rewind     send_data compressed_filestream.read, filename: 'export.zip', type: 'application/zip'   else     render xlsx: 'export', filename: filename, disposition: 'attachment'   end end 

if doesn't work, create issue on github, , after working can add documentation.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -