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

时间:2016-07-28 02:40:37

标签: ruby-on-rails ruby paperclip dokku

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

型号:

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

我有rails_12factor gem。这是 config 文件:

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

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:7)

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

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

答案 1 :(得分:2)

您可以创建一个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中,如果没有,只需将该文件夹更改为你上传文件的位置。