download csv

Hi, in my application i want to develop a code where when i click on download link , csv file get downloaded to client side. so for this i put <a href="/download_template.csv" style="color:#000000"> Download the group template (requires Excel).</a>(download_template.csv is my public dir.)    code in rhtml.its working correctly for IE but in Mozilla it directly open in browser instade that it ask for pop up, how should i do it?

reinhart

http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000228

     send_file( 'public/download_template.csv',                 :type => 'text/csv',                 :disposition => 'attachment',                 :stream => true,                 :filename => 'download_template.csv' )

Except for :type, the other options are the defaults.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Rob Biedenharn wrote:

As you could determine from the documentation link (if not from the documentation itself), this is part of ActionController. It goes into an action method and takes the place of a render or redirect.

Typically, you use send_file (or send_data) when the file is not visible in the standard directory structure (i.e., not under public/) or when you want to base the response on some calculation or property of the request.

-Rob

P.S. There are many who see these messages as email and not in the forum. Please do not post the same question in multiple places.

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com