Rails - Dokku - Paperclip: Every push to production breaks(404s) user uploaded images

走远了吗. 提交于 2019-12-12 03:16:53

问题


Running Rails 4 application on Digital Ocean with Dokku. Users can upload an image via paperclip. I can upload the images fine, and the application runs great and displays all images. Once I make a small change like a text change and I run $git push dokku master, all uploaded images 404.

Model:

class ProductImage < ActiveRecord::Base
  has_attached_file :image, default_url: "/images/:style/missing.png", 
  :path =>":rails_root/public/system/:attachment/:id/:basename_:style.:extension",
  :url =>"/system/:attachment/:id/:basename_:style.:extension",
  styles: { thumb: ["64x64#", :jpg], medium: ['200x200>', :jpg], 
    large: ['400x400>', :jpg] }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

  belongs_to :product
end

I have the rails_12factor gem. Here is the config file:

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.js_compressor = :uglifier
  config.assets.compile = true
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
end

Any help will be greatly appreciated!


回答1:


You can create a docker option to have it like persistent storage without a plugin. or example, create a folder like this

mkdir FOLDER_NAME

then you can add a docker option like this

dokku docker-options:add APP_NAME run "-v /home/dokku/FOLDER_NAME:/app/public/uploads"
dokku docker-options:add APP_NAME deploy "-v /home/dokku/FOLDER_NAME:/app/public/uploads"

this if you are working with a rails application and your uploads are in app/public/uploads, if don't, just change that folder to where you are uploading the files.




回答2:


Dokku act as heroku. You should use s3 or any storage service for uploaded image.

Or you can add persitent storage and mount to your dokku container app http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/



来源:https://stackoverflow.com/questions/38626259/rails-dokku-paperclip-every-push-to-production-breaks404s-user-uploaded-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!