# Download csv

**URL:** <https://www.ruby-forum.com/t/download-csv/138107>\
**Category:** Rails\
**Created:** [May 20, 2008, 9:53am UTC](https://www.ruby-forum.com/t/download-csv/138107 "2008-05-20T09:53:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 20, 2008, 9:53am UTC](https://www.ruby-forum.com/t/download-csv/138107/1 "2008-05-20T09:53:06Z")

</div>

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  
[  
Download the group template (requires Excel).](https://www.ruby-forum.com/download_template.csv)(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?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 20, 2008, 10:05am UTC](https://www.ruby-forum.com/t/download-csv/138107/2 "2008-05-20T10:05:31Z")

</div>

> **[link\_to\_file - Call File from .rhtml or .html.erb](http://teapoci.blogspot.com/2008/05/linktofile-call-file-from-rhtml-or.html)**
>
> Open app/helpers/application\_helper.rb Paste it : def link\_to\_file(name, file, \*args) if file\[0\] != ?/ file = "#{@request....

reinhart

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 20, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/download-csv/138107/3 "2008-05-20T13:47:29Z")

</div>

On May 20, 2008, at 3:53 AM, Sunny B. wrote:

> ## open in browser instade that it ask for pop up, how should i do it?

> **[ActionController::Streaming](https://api.rubyonrails.org/classes/ActionController/Streaming.html#M000228)**
>
> Allows views to be streamed back to the client as they are rendered. By default, Rails renders views by first rendering the template and then the layout.

```
 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 21, 2008, 7:01am UTC](https://www.ruby-forum.com/t/download-csv/138107/4 "2008-05-21T07:01:05Z")

</div>

Rob B. wrote:

> On May 20, 2008, at 3:53 AM, Sunny B. wrote:
> 
> > ## open in browser instade that it ask for pop up, how should i do it?
> 
> [ActionController::Streaming](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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

This code is OK ,but where to put this code in rhtml ya in separate  
method.  
if i am write new methos it give template error (rhtml missing),and in  
rhtml how i used it?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 21, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/download-csv/138107/5 "2008-05-21T14:27:29Z")

</div>

On May 21, 2008, at 1:01 AM, Sunny B. wrote:

> > ```
> > :stream => true,
> > 
> > ```
> 
> ## method. if i am write new methos it give template error (rhtml missing),and in rhtml how i used it?

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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
