简体   繁体   中英

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? 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM