在我的InvoicesController
里,我有这样的代码:
def index
@invoices = current_user.invoices
respond_to do |format|
format.html
format.xls
format.csv # not working!
end
end
在我的index.html.erb
视图中,我有以下两个下载链接:
<%= link_to "Download as Excel", invoices_path(:format => "xsl") %>
<%= link_to "Download as CSV", invoices_path(:format => "csv") %>
模板index.xsl.erb
和index.csv.erb
也存在。
第一个链接有效,即Excel文件被下载到用户的计算机中。但是CSV文件在浏览器中呈现而不是下载。
我该怎么做才能让用户也下载CSV文件?
感谢任何帮助。