rails 不会将数据作为文件发送 [英] rails won't send_data as file
本文介绍了rails 不会将数据作为文件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 Rails 方法时遇到问题:send_data
I'm having problems with Rails method: send_data
这是我的操作:
def export
send_data(current_user.contacts.to_csv,
type: 'text/csv; charset=utf-8; header=present',
disposition: 'attachment; filename=contacts.csv'
)
end
这不会提示下载,它只会在屏幕上呈现结果.我尝试了 pow
和 thin
服务器.
This will not promt for a download, it just render the result on the screen. I've tried both pow
and thin
servers.
我不知道我做错了什么?
I can't figure out what I'm doing wrong?
我正在使用 rails 4.0.0.beta
CURL 标头:
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-UA-Compatible: chrome=1
< X-XHR-Current-Location: /contacts/export
< Content-Disposition: attachment; filename=contacts.csv
< Content-Transfer-Encoding: binary
< Content-Type: text/csv; charset=utf-8; header=present
< Cache-Control: private
< ETag: "48d3d8bd1c8d25cafb82ab705e4875ab"
< Set-Cookie: request_method=GET; path=/
< X-Request-Id: c2588883-f3f9-4f68-8a8c-0de758c47288
< X-Runtime: 0.185206
< Connection: close
< Server: thin 1.5.0 codename Knife
推荐答案
我想通了.
是涡轮链接把这一切搞砸了.我在导出链接中添加了 data-no-turbolink,现在它按预期工作了.
It was turbolinks that was messing it all up. I added data-no-turbolink to the export link and now it works as expected.
这篇关于rails 不会将数据作为文件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文