rails 文件下载功能

 

controller:

class DownController < ApplicationController  

   def down_file

    send_file "public/files/"+params[:filename] unless params[:filename].blank?  

   end  

end 

view:

     <%= link_to "下载文件", :action => "down_file", :filename => "down.txt" %>

 

或者直接放置于public中

<%= link_to "下载文件", "1.xls" %>

你可能感兴趣的:(Rails)