Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How to download a previously uploaded document?

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 %>
like image 790
Barbared Avatar asked Jul 27 '12 14:07

Barbared


1 Answers

I don't use Carrierwave but I guess it's similar to Paperclip.

Therefore you should be able to use something like this

 link_to 'Download file', user.file.url

This is assuming you have a user instantiated object from a Model with a 'file' carrierwave attribute. Replace this with your attribute name.

like image 68
Anthony Alberto Avatar answered Sep 19 '22 13:09

Anthony Alberto