Reputation: 13721
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? 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
Thanks!
Upvotes: 1
Views: 233
Reputation: 76774
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
Upvotes: 4