如果我点击这个url: http://localhost:3000/reports/action.xlsx
,它会显示一个生成的xlsx文件。
如果我有一个这样的link_to
:
<%= link_to 'Export to Excel', reports_affirmative_action_path, :format => :xlsx %>
生成到该页面的链接:http://localhost:3000/reports/action
为什么我的link_to与:format => :xlsx
不链接到正确的路径?
您的link_to
和path
稍微偏离。你想要
<%= link_to('Export to Excel', reports_affirmative_action_path(format: :xlsx)) %>
格式是path
帮助器的参数,而不是link_to
。
适合我
<%= link_to('Export to Excel', reports_affirmative_action_path(:format =>:xls)) %>
使用:xls代替:xlsx