hideto 发表于 2013-1-24 21:16:20

每天一剂Rails良药之Rendering CSV From Your Actions

有时候我们需要输出CommaSeparated Values(CSV)等各种形式的输出来满足用户的需要:
class ExportController < Application ontrollerdef orders    content_type = if request.user_agent =~ /windows/i                     'application/vnd.ms-excel'                   else                     'text/csv'                   end    CSV::Writer.generate(output = "") do |csv|      Order.find(:all).each do |order|      csv <<       end    end    send_data(output, :type=> content_type, :filename => "orders.csv")endend
页: [1]
查看完整版本: 每天一剂Rails良药之Rendering CSV From Your Actions