Mime Type CSV Bug in Rails 1.2.2
Does this warning look familiar?
"mime_type.rb:48: warning: already initialized constant CSV"
Here's why. CSV was added as a pre-defined mime type to Rails 1.2, but a very minor bug causes the mime type to not be available for use. So you have to define it yourself using the code below (usually in environment.rb):
Mime::Type.register 'text/csv', :csv, %w('text/comma-separated-values')
This code then causes the above warning to appear.
I did some digging and found the error in mime_type.rb. I considered submitting a ticket / patch, but right now the Rails Trac is down and I can't do much with it. I was able to look at the trunk source and see that mime_type.rb has been re-written, so this problem will go away in future versions of Rails (or if you are using Edge Rails).
Here's a quick fix that I am using in one of my production application's (which is frozen to Rails 1.2.2) environment.rb -
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
The above line will fix the issue for Rails 1.2.2, and will be ignored if the specific bug is ever fixed in the current structure of mime_type.rb.