如何在ruby中制作下载链接

时间:2013-08-21 07:20:52

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

我的控制器: -

def download
    send_file( "/123.zip" )
  end

我的下载视图: -

<h1>Hello World</h1>

从我调用下载选项: -

<%= link_to 'download', :class => "btn btn-large btn-danger" do %>

请帮助我如何建立链接.. 现在这显示错误

Sent file /123.zip (1.0ms)
DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:erb] instead. (called from c:in `find_template':)
  Rendered layouts/error/application.html.erb within layouts/application (0.0ms)
  Rendered layouts/_sidebar.html.erb (13.0ms)
Completed 404 Not Found in 60ms (Views: 50.0ms | ActiveRecord: 4.0ms)

1 个答案:

答案 0 :(得分:1)

建立您的链接: -

<%= link_to 'download', "/PatientManagement/download", :class => "btn btn-large btn-danger"%>

在控制器中

send_file( "<absolute path to file/123.zip" )

您也可以使用Rails.root获取Rails根目录。