html - How to make a file 'download' when clicked in Windows IE -


i have button in form tag generates csv file , prompts download when user clicks it.

when try accomplish in ie, ie tries open file ie shouldn't. want download file.

my html :

<form accept-charset="utf-8" method="post" action="/generate_csv?calc[]total_interest=189.08">   <div style="margin: 0px; padding: 0px; display: inline;"><input name="utf8" value="✓" type="hidden">     <input name="authenticity_token" value="4o1dedofbbdoc3scpnhdaqpptpfm5nittoryqa0au5k=" type="hidden">   </div>   <input id="print_csv" name="commit" value="print csv" type="submit"> </form> 

my rails controller :

headers['content-disposition'] = "attachment;" send_data(csv_string,   :type => 'text/csv; charset=utf-8; header=present; disposition=attachment',   :filename => @filename,   :disposition => 'attachment') 

any ideas how accomplish this?

i try following. in controller, when generate csv file sending using send_data or send_file. correct? if so, need set disposition 'attachment' instead of sending file or data. example:

send_data @csv, :type => 'text/csv', :disposition => 'attachment', :filename => 'generate_csv.csv' 

or

send_file '/path/to.csv', :type => 'text/csv', :disposition => 'attachment' 

another thing can modify routes include format. example:

match 'generate_csv.csv' => 'csv#generate_csv' 

you can convert post request request this:

<%= link_to "print csv", '/generate_csv?calc[]total_interest=189.08' %> 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -