2013-08-21 20 views
0

我的控制器: -如何使下載鏈接在紅寶石

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) 
+0

你可以粘貼你的'rake routes'命令輸出嗎? –

+0

我是新來的,所以你的意思是我的路線? 匹配「/ PatientManagement/download」=>'current_inpatient#download' –

+0

打開您的終端,轉至您的項目目錄,然後執行此命令'rake routes'。這會列出項目中所有可用的路徑。 –

回答

1

讓你的鏈接是這樣的: -

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

並在控制器

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

您還可以使用Rails.root讓Rails的根目錄。

+0

嘿感謝它現在工作..你能告訴我如何添加一個警告框,要求繼續下載 –

+0

<%= link_to'下載',「/ PatientManagement/download」,:class =>「btn btn-large btn-danger」,:confirm =>「你確定嗎? %>添加警告框 –

+0

它是工作感謝阿曼.. –