[英]Paperclip download file Rails 4.0
I am now able to upload files into my Rails app using Paperclip, but I was wondering if anyone could help me with how to download it? 我现在可以使用Paperclip将文件上传到我的Rails应用程序中,但是我想知道是否有人可以帮助我下载它? I have a Contract model that has an attachment called Avatar.
我有一个带有附件的“合同”模型,称为“头像”。 So far I tried the following:
到目前为止,我尝试了以下方法:
Currently I have a controller: 目前我有一个控制器:
class DownloadController < ApplicationController
def download_file
send_file '@contract.avatar.url'
end
end
In my contracts/show view I have: 在我的合同/显示视图中,我有:
<%= link_to ('download'), {:controller => 'downloads', :action => 'download_file'})
My routes: 我的路线:
get "downloads/download_file"
The error I am getting right now is "Uninitialized constant DownloadsController 我现在得到的错误是“未初始化的常量DownloadsController
Thanks! 谢谢!
The error you have is pretty self-explanatory if you know where to look : 如果您知道要查找的位置,则错误很容易解释:
Uninitialized constant Download**s**Controller
See how it's looking for a plural? 看到它寻找复数了吗?
There are two ways to solve this: 有两种解决方法:
Routes 路线
get "downloads/download_file", to: "download#download_file"
- --
Controller 控制者
#app/controllers/downloads_controller.rb
class DownloadsController < ApplicationController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.