原创作者: hideto
阅读:1424次
评论:0条
更新时间:2011-05-26
有时候我们需要输出Comma Separated Values(CSV)等各种形式的输出来满足用户的需要:
class ExportController < Application ontroller def 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 << [order.id, order.price, order.purchaser, order.created_at] end end send_data(output, :type=> content_type, :filename => "orders.csv") end end
评论 共 0 条 请登录后发表评论