无法获取rails以启动csv下载
有一个表单提交'send_report.csv'
def send_report
if Survey.passphrase? params[:passphrase]
respond_with do |format|
format.csv{
report = CSV.generate do |csv|
csv << ["csv data"]
end
send_data report, :type => 'text/csv', :disposition => "attachment", :filename => "file.csv"
}
end
else
redirect_to report_path
end
end
服务器似乎一切都正常了......
Started GET "/send_report.csv?utf8=%E2%9C%93&passphrase=123&commit=submit" for 127.0.0.1 at 2013-12-12 16:12:19 -0800
Processing by MainController#send_report as CSV
Parameters: {"utf8"=>"✓", "passphrase"=>"123", "commit"=>"submit"}
Rendered text template (0.0ms)
Sent data file.csv (0.7ms)
Completed 200 OK in 5ms (Views: 0.6ms | ActiveRecord: 0.0ms)
但浏览器中没有出现下载界面。我已经阅读了关于这个主题的其他SO帖子,但没有看到解决方案。想法?
答案 0 :(得分:2)
您的代码没有任何问题(仔细测试)。也许是因为你的浏览器?
答案 1 :(得分:0)
所以我的问题是rails jquery mobile gem在页面上插入某种控件,搞乱了csv下载的启动,@ justin感谢你查看我的代码,你说得对。