【发布时间】:2010-07-27 15:06:34
【问题描述】:
我正在运行 Rails 2.2.3。我有一个控制器用于管理上传和下载文件。我已成功链接到视图上的文件以允许用户下载,但是当下载对话框打开时,它只显示一个保存文件选项。我也想提供“打开方式”选项。我在 Ubuntu 10 上使用 Firefox 3.6。
这是用于将文件“发送”给用户的控制器:
def show
@document = Document.find(params[:id])
respond_to do |format|
if File.exist?("#{RAILS_ROOT}/#{@document.path}")
format.html { send_file "#{RAILS_ROOT}/#{@document.path}" }
else
flash[:error] = "File #{@document.path} does not exist!"
format.html { redirect_to(:back) }
end
end
结束
【问题讨论】:
标签: ruby-on-rails ruby