再会!我想下载自动生成的文件 qwerty.csv,但它只返回文本“12345”(没有文件)。你能帮助我吗?
用户界面
<script type="text/javascript">
function getCsv() {
var ids = getSelectedRecordIds();
$.post('/payments/form_csv.csv', { ids: ids }, function(data) {});
}
</script>
控制器
def form_csv
csv_string = CSV.generate do |csv|
csv << ["12345"]
end
respond_to do |format|
format.csv {
send_data csv_string, :type => 'text/csv; charset=utf-8; header=present', :disposition => "attachment; filename=qwerty.csv", :filename => "qwerty.csv"
}
end
end
在控制台中
Started POST "/payments/form_csv.csv" for 127.0.0.1 at 2012-06-18 18:18:11 +0400
Processing by PaymentsController#form_csv as CSV
Parameters: {"ids"=>["18\n\t "]}
Rendered text template (0.0ms)
Sent data qwerty.csv (0.4ms)
Completed 200 OK in 2ms (Views: 0.4ms | ActiveRecord: 0.0ms)
但是没有文件提示...