Rails: How to download a previously uploaded document?

Viewed 10541

I need my user to upload documents such ad pdf and txt on their profile. And I did that using Carrierwave, so I have a list of documents with titles and urls.

But how can I make other users download those files? Do I have to use a gem or is there something native I don't even know since I am very new to rails?

Thanks

EDIT:

society.rb

class Society < ActiveRecord::Base
  ...
  has_many :documents, :dependent => :destroy
end

document.rb

class Document < ActiveRecord::Base
  belongs_to :society    
  mount_uploader :url, DocumentUploader    
end

And then this in the view I want to download files:

  <% @society.documents.each do |doc| %>
    <%= link_to "Download it", doc.url %>    //url is the column name of the saved url
  <% end %>
3 Answers

Or you can put anchor tag:

in your controller:

@doc = "query to get the document name from your database"
@docpath = request.base_url+"/uploads/"+@doc

in your view:

<a href="@docpath" download>Download File</a>.
Related