Problem concerning CSV Mime Type

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?

See:
www.pdatasolutions.com/blog/archive/2007/02/mimetypecsvbug_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.

Luke I. wrote:

See:
www.pdatasolutions.com/blog/archive/2007/02/mimetypecsvbug_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!