With recent update to Rails 2.3 we found that we cant' stream CSV with FasterCSV anymore
render :text => Proc.new { |response, output|
preamble = opts.delete(:preamble)
postscript = opts.delete(:postscript)
output << preamble if preamble
csv = FasterCSV.new(output, opts)
yield csv
output << postscript if postscript
}
Turns out AcvtionController::Response lost it's method <<
*** Exception NoMethodError in application (undefined method `<<' for #<ActionController::Response:0xaa90d1c>) (process 26482):
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/fastercsv-1.4.0/lib/faster_csv.rb:1459:in `<<'
Small monkey patching on the fly to the rescue
render :text => Proc.new { |response, output|
preamble = opts.delete(:preamble)
postscript = opts.delete(:postscript)
output.write preamble if preamble
#monkey patch /duck typing. 2.3 rails ActionController::Response doesn't have <<, only write
def output.<<(*args)
write(*args)
end
csv = FasterCSV.new(output, opts)
yield csv
output.write postscript if postscript
}