I have uploaded images with carrierwave under the public folder. For security reason, I'm going to change the folder to under the root.
Althogh I referred to the post How to: Secure Upload and created carrierwave.rb, I don't know how to write the path uploaded by carrierwave.
How can I display images under private folder?
image_uploader.rb
class ImageUploaader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
I created \config\initializers\carrierwave.rb
CarrierWave.configure do |config|
config.permissions = 0600
config.directory_permissions = 0700
config.root = Rails.root
end
I also created images_controller.rb
class ImagesController < ApplicationController
#I tried some, but doesn't work
end
I have used the following view to display images.
\views\articles\ _article.html.erb
<% article.photos.each do |photo| %>
<%= image_tag(photo.image_url(:thumb).to_s, class: :thumb) if photo.image? %>
<% end %>
It would be appreciated if you could specify the code in routes.rb
, images_controller.rb
and _article.html.erb
.