Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The approach that I took with a Rails 2.3.8 app was to spawn a new thread to handle the csv parsing and then use an AJAX call to check the server to see if the file was ready (I relied on File.mtime).</p> <p>Just ripped it out of the app to post here so I've removed <strong>alot</strong> of the csv parsing code, and haven't included all of the views</p> <p>sorry end of the day rush :D</p> <p>controllers/exports_controller.rb</p> <pre><code> class ExportsController &lt; ApplicationController require 'fastercsv' require 'generic_agent' require 'generic_record' def listing @this_filepath = "../html/whatever/" &lt;&lt; Time.now.strftime("%I:%M:%S_%d:%m:%y") &lt;&lt; ".csv" @spawn_id = spawn(:nice =&gt; 1) do FasterCSV.open(@this_filepath, "w") do |csv| csv &lt;&lt; [ "outbreak_id"] end end render :update do |page| page.replace_html 'export_status', :partial =&gt; 'export_status_partial' end end def send_export @this_filepath = params[:with] csv_file = File.open(@this_filepath.to_s, 'r') csv_string = "" csv_file.each_line do |line| csv_string &lt;&lt; line end send_data csv_string, :filename =&gt; "export.csv", :type =&gt; 'text/csv; charset=iso-8859-1; header=present', :disposition =&gt; "attachment; filename=export.csv" #send_file @this_filepath.to_s, :stream =&gt; false, :type=&gt;"text/csv", :x_sendfile=&gt;true #send_data csv_string, :filename =&gt; export.csv #File.delete(@this_filepath.to_s) end def export_checker filename_array = params['filename'].split(/\//) @file_found = 0 @file_ready = 0 @file_size = File.size(params['filename']) @this_filepath = params['filename'] if File.exists?(params['filename']) release_time = Time.now - 5.seconds if File.mtime(params['filename']).utc &lt; release_time.utc @file_found = 1 @file_ready = 1 @file_access_time = File.mtime(params['filename']) @file_release_time = release_time @file_size = File.size(params['filename']) else @file_found = 1 @file_ready = 0 @file_size = File.size(params['filename']) end else @file_found = 0 @file_ready = 0 @file_size = File.size(params['filename']) end render :action =&gt; "export_checker" end end </code></pre> <p>views/exports/export_checker.rjs</p> <pre><code>if @file_found == 1 &amp;&amp; @file_ready == 1 &amp;&amp; @file_size &gt; 0 page.replace_html 'link_to_file', :partial =&gt; "export_ready" if @file_release_time page.replace_html 'notice', "&lt;div&gt;Completed #{@file_release_time.strftime("%I:%M:%S %A %d %B %Y")} :: file size #{@file_size.to_s}&lt;/div&gt;" end page.visual_effect :highlight, 'link_to_file', :endcolor =&gt; '#D3EDAB' elsif @file_found == 1 page.replace_html 'link_to_file', "&lt;div&gt; File found, but still being constructed.&lt;/div&gt;&lt;div&gt;#{@this_filepath.to_s}&lt;/div&gt;" page.visual_effect :highlight, 'link_to_file', :endcolor =&gt; '#FF9900' else page.replace_html 'link_to_file', "&lt;div&gt; File not found @file_found #{@file_found.to_s} @file_ready #{@file_ready.to_s}&lt;/div&gt;" page.visual_effect :highlight, 'link_to_file', :endcolor =&gt; '#FF0000' end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload