我对红宝石很陌生。我有一个问题,如何一键导出两个文件。
在现有版本中,我一次只能通过调用 'def stream_csv' 生成一个文件,但是当我尝试调用它两次以获取两个文件时,我收到一条错误消息,指出“ActionController::DoubleRenderError (Can only每次操作渲染或重定向一次):“我猜,这是因为渲染。
这是stream_csv的源代码:
def stream_csv
require 'fastercsv'
filename = params[:action] + ".csv"
#this is required if you want this to work with IE
if request.env['HTTP_USER_AGENT'] =~ /msie/i
headers['Pragma'] = 'public'
headers["Content-type"] = "text/plain"
headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
headers['Expires'] = "0"
else
headers["Content-Type"] ||= 'text/csv'
headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
controller.response.headers["Content-Transfer-Encoding"] = "binary"
end
render :text => Proc.new { |response, output|
csv = FasterCSV.new(output, :row_sep => "\r\n")
yield csv
}
end
end
是否可以一键创建两个文件?如果是,我该怎么做?