Rails设置下载链接

时间:2013-08-30 11:17:52

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

以下链接将列出所有客户

localhost:3000/clients

如果我直接输入以下链接,xls文件将被下载

localhost:3000/clients.xls

这是我的路线

match 'client' => 'Clients#clients_new'

如何为此文件提供下载链接

我的观看文件名在clients_new.html.erb clients_controller clients_new我的行为为<p><%= link_to 'Download as Excel', newclients_path(:format => :xls) %></p>

我试过

undefined method `newclients_path' for #<#<Class:0x999e02c>:0x9eeee3c>

正在抛出错误

clients_newClients GET    /clients/newClients(.:format)          clients#newClients

佣金路线

{{1}}

2 个答案:

答案 0 :(得分:0)

试试这个:

Routes

match 'client' => 'Clients#clients_new'

Link

<p><%= link_to 'Download as Excel', client_path(:format => :xls) %></p>

答案 1 :(得分:0)

根据您的rake routes

<%= link_to 'Download as Excel', client_path(:format => :xls) %>