Set path for original images using paperclip in Rails?

后端 未结 2 383
再見小時候
再見小時候 2020-12-24 09:27

The situation

I have a simple model with an attached image using paperclip, which has a couple of processed styles for it (thumbnail, full, feature). At this point

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 10:26

    I would recommend using a custom interpolation that will place your original files outside the public directory. Something like this:

    
    Paperclip.interpolates :maybe_public do |attachment, style|
      style == :original ? "private" : "public"
    end
    
    has_attached_file :image, :path => ":rails_root/:maybe_public/:attachment..."
    

    This will save your :original files in a non-publicly accessible directory for protection, but still allow Paperclip access. And it will keep your thumbnails in the public directory for standard access.

提交回复
热议问题