# Setting header in views?

**URL:** <https://www.ruby-forum.com/t/setting-header-in-views/157655>\
**Category:** Rails\
**Created:** [January 14, 2009, 5:50am UTC](https://www.ruby-forum.com/t/setting-header-in-views/157655 "2009-01-14T05:50:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [January 14, 2009, 5:50am UTC](https://www.ruby-forum.com/t/setting-header-in-views/157655/1 "2009-01-14T05:50:57Z")

</div>

currently iam using FasterCSV to render csv pages

format.csv do  
csv\_string = FasterCSV.generate do |csv|  
# header row  
csv \<\< @query\_result[0].keys

```
      @query_result.each do |x|
        csv << x.values
      end
    end
    #send it to the browser
    send_data csv_string,
      :type => 'text/csv; charset=iso-8859-1; header=present',
      :disposition => "attachment; filename=#{'data'}.csv"
  end

```

i wanted to contain the “display codes” inside a view so i tried using  
respond\_to do |format|  
format.csv  
and having a matching show.csv.erb

but i cant set the header information  
-\> send\_data csv\_string,  
:type =\> ‘text/csv; charset=iso-8859-1; header=present’,  
:disposition =\> “attachment; filename=#{‘data’}.csv”  
inside the view itself

anyway to do it ?

---

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [March 7, 2009, 1:32pm UTC](https://www.ruby-forum.com/t/setting-header-in-views/157655/2 "2009-03-07T13:32:39Z")

</div>

stubmbled across this message right after looking at this message.

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/fea26c9c3c01ba93?pli=1](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/fea26c9c3c01ba93?pli=1)

Maybe it will help you. Good Luck!
