Rails link_to :format =>:xlsx 不生成指向 .xlsx 路径的链接 [英] Rails link_to :format => :xlsx not generating link to .xlsx path

查看:37
本文介绍了Rails link_to :format =>:xlsx 不生成指向 .xlsx 路径的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我点击这个网址:http://localhost:3000/reports/action.xlsx 它会显示一个生成的 xlsx 文件.

If I hit this url: http://localhost:3000/reports/action.xlsx it shows a generated xlsx file.

如果我有这样的 link_to:

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

它会生成一个指向此页面的链接:http://localhost:3000/reports/action

It generates a link to this page: http://localhost:3000/reports/action

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

Why does my link_to with :format => :xlsx not link to the correct path?

推荐答案

您的 link_topath 稍微偏离了.你想要

Your link_to and path are slightly off. You want

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

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

Where the format is an argument to the path helper, not link_to.

这篇关于Rails link_to :format =>:xlsx 不生成指向 .xlsx 路径的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆