1
我的用户可以生成一些数据的报告,并决定他们想要的格式。Rails 3 CSV和XLS导出不提供文件扩展名
他们可以选择HTML,CSV或XLS
这是表单(省略了数据的东西,这只是格式选择)
<%= form_tag "/report", :method => :get %>
Format <select id='format' name='format'>
<option value='html' selected='selected'>View in browser (HTML)</option>
<option value='csv'>Export to CSV file</option>
<option value='xls'>Export to exel (XLS)</option>
</select>
<%= submit_tag "Make report", :class => 'submit' %>
这种形式进入这个动作
def report
#...Again omitting data stuff
respond_to do |format|
format.html
format.csv
format.xls
end
end
我有相应的视图文件。
像report.xls.erb
在我的日志我得到
Processing by ..Controller#report as XLS
但是,浏览器下载没有扩展文件。
如果我将form_tag行更改为此。
<%= form_tag "/report.xls", :method => :get %>
该文件获得.xls扩展名。
我已经设置了XLS mime_types
我怎样才能设置表单的格式?