Rails中的link_to :format => :xlsx不生成.xlsx路径的链接。

25
如果我点击这个网址: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时没有链接到正确的路径?


你的控制器代码是什么样子的?在这个特定操作的响应块中,你有什么?此外,你是否尝试将一些文件导出为.xsl格式? - Deej
控制器不相关,因为直接访问URL可以工作。但是我在我的respond_to块中有一个format.xlsx。 - Catfish
2个回答

48

你的link_topath略微偏离了。你需要:

<%= link_to('Export to Excel', reports_affirmative_action_path(format: :xlsx)) %>

在这里,格式是作为参数传递给 path 辅助函数的,而不是 link_to


-3

适用于我
<%= link_to('导出到Excel', reports_affirmative_action_path(:format => :xls)) %>

使用:xls而不是:xlsx


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接