# Problem concerning CSV Mime Type

**URL:** <https://www.ruby-forum.com/t/problem-concerning-csv-mime-type/86909>\
**Category:** Rails\
**Created:** [February 26, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/problem-concerning-csv-mime-type/86909 "2007-02-26T21:14:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [February 26, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/problem-concerning-csv-mime-type/86909/1 "2007-02-26T21:14:24Z")

</div>

Hello,

I have an application that should be able to export a list of users as  
CSV.

So I put  
Mime::Type.register “text/csv”, :csv  
into my environment.rb, and added this code to my UserController’s index  
action:

```
  format.csv do
    require 'csv'
    CSV::Writer.generate(csv_string = "", ',') do |csv|
      csv << ["login","attribute1","attribute2"]
      @users.each { |user| csv << [user.login, user.email] }
    end
    send_data csv_string, :filename => "users.csv"
  end

```

All this is working fine, but each time I start my “ruby  
script/console”, I get the following error:  
./script/…/config/…/config/…/vendor/rails/actionpack/lib/action\_controller/mime\_type.rb:48:  
warning: already initialized constant CSV

The error disappears, as soon as I remove the Mime Type entry in the  
environment.rb. But of course this breaks the CSV export action.

So the app is behaving fine, but what causes the error and how can I get  
rid of it?

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [February 26, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/problem-concerning-csv-mime-type/86909/2 "2007-02-26T21:19:58Z")

</div>

See:  
[www.pdatasolutions.com/blog/archive/2007/02/](http://www.pdatasolutions.com/blog/archive/2007/02/)_mime __type__ csv__bug\_in_\*  
rails\*\_122.html

This, however, seems to be down, so just search for “rails mime type  
csv” on  
google, find the link to that page (first link, for me), and look at the  
cached version.

---

<div class="post-metadata">

**Author:** ![ralph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f475e1/32.png) [@ralph](https://www.ruby-forum.com/u/ralph)\
**Post date:** [March 10, 2007, 11:01am UTC](https://www.ruby-forum.com/t/problem-concerning-csv-mime-type/86909/3 "2007-03-10T11:01:06Z")

</div>

Luke I. wrote:

> See:  
> [www.pdatasolutions.com/blog/archive/2007/02/](http://www.pdatasolutions.com/blog/archive/2007/02/)_mime __type__ csv__bug\_in_\*  
> rails\*\_122.html
> 
> This, however, seems to be down, so just search for “rails mime type  
> csv” on  
> google, find the link to that page (first link, for me), and look at the  
> cached version.

Thank you Luke!
