# Send some text as a csv file?

**URL:** <https://www.ruby-forum.com/t/send-some-text-as-a-csv-file/166770>\
**Category:** Rails\
**Created:** [April 29, 2009, 11:57am UTC](https://www.ruby-forum.com/t/send-some-text-as-a-csv-file/166770 "2009-04-29T11:57:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 29, 2009, 11:57am UTC](https://www.ruby-forum.com/t/send-some-text-as-a-csv-file/166770/1 "2009-04-29T11:57:44Z")

</div>

I have a table on a page, and i want a link to download the table data  
as a csv. One way to do this would be to have my model class build a  
file, and pass the filename back to the controller, which uses send\_file  
to send it to the user. But, this seems a bit heavy handed - it’s a  
small amount of data, which is subject to change, and i don’t want a  
load of files hanging around if i can help it.

Is there a simple way to just generate some text and push it back as a  
file? eg

1. use a simple view which is rendered normally in the controller, and  
change the link\_to tag to download the results instead of render it?  
(if so, how do i set the filename?)

2. have a normal link\_to tag and have the controller build the text  
itself (it’s just going to be an array join effectively) and push the  
text back as a file.

Any advice welcome - thanks!  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 29, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/send-some-text-as-a-csv-file/166770/2 "2009-04-29T12:12:20Z")

</div>

On Apr 29, 10:57 am, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have a table on a page, and i want a link to download the table data  
> as a csv. One way to do this would be to have my model class build a  
> file, and pass the filename back to the controller, which uses send\_file  
> to send it to the user. But, this seems a bit heavy handed - it’s a  
> small amount of data, which is subject to change, and i don’t want a  
> load of files hanging around if i can help it.

Have a look at send\_data.

Fred

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 29, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/send-some-text-as-a-csv-file/166770/3 "2009-04-29T12:28:06Z")

</div>

Perfect, thanks (again!) Fred. I should have worked that out myself  
really…

max
