I have Catalogone that has an attribute called file:
class Catalog < ActiveRecord::Base
mount_uploader :file, CatalogUploader
How to create a link that will display this file in a browser?
I tried
<%= link_to "zzzz", catalog.file_url %>
but when i click this link it just gives a routing error
Routing Error
No route matches [GET] "/Users/emai/Documents/mysite/catalogs/2/vegetarian.png"
And the URL-address looks wrong: http://localhost:3000/Users/emai/Documents/mysite/catalogs/2/vegetarian.png. I know that pic exists because I created a link to download the file and it worked correctly. However, I want to show the pic ..
CatalogUploader:
class CatalogUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
if Rails.env.test? || Rails.env.cucumber?
"#{Rails.root}/public/test/file_uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
else
"#{Rails.root}/catalogs/#{model.id}"
end
end
end
source
share