Reputation: 2502
I've just noticed that after I redeploy my rails app to production with cap deploy:migrations
any image that I've uploaded via my admin forms (such as creating a testimonial with an avatar image) that the image links are now broken. The images appear fine as long as I don't redeploy any code, which is not desired since I push code changes quite frequently. I assume this is related to the way capistrano creates the file structure in 'releases' for each deployment but I'm not sure how to go about fixing this issue.
I'm also not tracking public/uploads
with git since I don't want the fake content I use on localhost to appear in production.
So, before my latest code push, I had all the images there since I just added them. Now, after the push there are no images:
Here are the files that I believe are relevant (let me know if there is one that you need to see beyond these):
avatar_uploader.rb:
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :resize_to_fit => [200, 200]
def extension_white_list
%w(jpg jpeg gif png)
end
end
Upvotes: 2
Views: 1256
Reputation: 3311
By default, Capistrano links public/system
directory. So to persist your images, just change
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
to
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
Upvotes: 4
Reputation: 199
Seems like you don't configure linked_dirs
variable in your deploy.rb (in case of Capistrano 3) or not specify sym-link to your public/uploads
from shared/public/uploads
(in case of Capistrano 2).
Without it all deploy will "override" public/uploads
directory.
Here is more details.
Upvotes: 0