Rails – Dokku – Paperclip:每次推送到生产中断(404s)用户上传的图像

使用Dokku在Digital Ocean上运行Rails 4应用程序。 用户可以通过回形针上传图像。 我可以上传图像,应用程序运行良好并显示所有图像。 一旦我做了一个像文本更改的小改动,我运行$ git push dokku master,所有上传的图像404。

模型:

class ProductImage ":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 

我有rails_12factor gem。 这是配置文件:

 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 

任何帮助将不胜感激!

您可以创建一个docker选项,使其像没有插件的持久存储一样。 或者,例如,创建一个这样的文件夹

 mkdir FOLDER_NAME 

然后你可以像这样添加一个docker选项

 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" 

如果你正在使用rails应用程序并且你的上传是app / public / uploads,如果没有,只需将该文件夹更改为上传文件的位置即可。

Dokku充当了heroku。 您应该为上传的图像使用s3或任何存储服务。

或者您可以添加persitent存储并安装到您的dokku容器应用程序http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/