我的机器上有一个文件的路径,我想为其设置下载链接。这是我正在尝试的:
在我的模型中:
class Exam < ActiveRecord::Base
attr_accessible :data, :full_path
has_attached_file :image,
:path => :full_path
end
我的控制器看起来像这样:
def download
@exam = Exam.find(params[:id])
send_file @exam.image.path, :x_sendfile => true
end
而我的观点:
<%= link_to "Download", download_exam_path(@exam) %>
现在,当我单击下载时,我收到此错误:can't convert nil into String
我知道一个事实,:full_path
其中包含我的文件的正确路径。我怎样才能解决这个问题?
完整错误:
TypeError in ExamsController#download
can't convert nil into String
Rails.root: /Users/Ryan45/Programming/rails_projects/oldV_rails_project
Application Trace | Framework Trace | Full Trace
app/controllers/exams_controller.rb:83:in `download'
Request
Parameters:
{"id"=>"392"}
Show session dump
Show env dump
Response
Headers:
None