【问题标题】:Rails link_to :format => :xlsx not generating link to .xlsx pathRails link_to :format => :xlsx 未生成指向 .xlsx 路径的链接
【发布时间】:2013-04-16 17:48:53
【问题描述】:

如果我点击这个网址: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

为什么我的带有:format =&gt; :xlsx 的link_to 没有链接到正确的路径?

【问题讨论】:

  • 你的控制器代码是什么样子的。在此特定操作的响应块中,您有吗?此外,您是否尝试将某些文件导出为 .xsl
  • 控制器无关紧要,因为直接点击 url 有效。但我的 response_to 块中确实有一个 format.xlsx。

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

您的link_topath 略有偏差。你想要的

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

格式是path 助手的参数,而不是link_to

【讨论】:

    【解决方案2】:

    适合我
    :xls)) %>

    使用 :xls 代替 :xlsx

    【讨论】:

      猜你喜欢
      • 2017-03-09
      • 2019-03-20
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 2016-02-25
      • 2018-07-08
      相关资源
      最近更新 更多