---
title: "ruby on rails 实现文件的下载"
author: "PBFox"
date: "2007-05-11T16:02:00Z"
tags: []
slug: "ruby-on-rails"
draft: false
lastmod: "2007-05-11T16:02:00Z"
id: 479295
url: "https://developerwork.iteye.com/blog/479295"
---

Controller:  
把这段代码放入  
download\_controller中  
class DownloadController &lt; ApplicationController  
def download  
send\_file "public/files/"+params\[:filename] unless params\[:filename].blank?  
end  
end

View:  
把这段代码放入  
download.rhtml中  
&lt;%=link\_to 'download',:action=&gt;'download',:filename=&gt;'trustee070328.zip'%&gt;

这样就可以实现下载public/files文件夹中的trustee070328.zip文件了