# Best way to generate a text or csv file for user to download

**URL:** <https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645>\
**Category:** Rails\
**Created:** [May 21, 2007, 5:29am UTC](https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645 "2007-05-21T05:29:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [May 21, 2007, 5:29am UTC](https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645/1 "2007-05-21T05:29:01Z")

</div>

lo there all,

i need to be able to generate a link to a dynamically created text or  
csv file when a user hits a link or button ( don’t know yet ). But  
since the file is going to be generated on the fly, i need an action  
to actually create it.

Does anyone have an idea of how the best way to do this would be?

thanks

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [May 21, 2007, 6:34am UTC](https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645/2 "2007-05-21T06:34:06Z")

</div>

On May 20, 2007, at 10:27 PM, nephish wrote:

> i need to be able to generate a link to a dynamically created text or  
> csv file when a user hits a link or button ( don’t know yet ). But  
> since the file is going to be generated on the fly, i need an action  
> to actually create it.
> 
> Does anyone have an idea of how the best way to do this would be?

You’ll probably want to take a look at the send\_file method:

[http://rails.rubyonrails.org/classes/ActionController/](http://rails.rubyonrails.org/classes/ActionController/)  
Streaming.html#M000091

James.

–  
James S.

> **[Processing Greenbelt 2009](https://jystewart.net/2009/09/08/processing-greenbelt-2009/)**
>
> We did, in fact, make a newspaper. The hour or so after my last post were more than a little stressful, but the results (a few typos and a printing hiccup that most certainly wasn’t our fault…

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [May 21, 2007, 7:46am UTC](https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645/3 "2007-05-21T07:46:10Z")

</div>

Also you might find fastercsv useful:

[http://fastercsv.rubyforge.org/](http://fastercsv.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [May 21, 2007, 12:13pm UTC](https://www.ruby-forum.com/t/best-way-to-generate-a-text-or-csv-file-for-user-to-download/104645/4 "2007-05-21T12:13:12Z")

</div>

thanks, gents, will check it out.
