Rails - Dokku - Paperclip:每次推送到生产中断(404s)用户上传的图像 [英] Rails - Dokku - Paperclip: Every push to production breaks(404s) user uploaded images

查看:49
本文介绍了Rails - Dokku - Paperclip:每次推送到生产中断(404s)用户上传的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

型号:

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.这是配置文件:

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

任何帮助将不胜感激!

推荐答案

你可以创建一个 docker 选项,让它像没有插件的持久存储一样.或者例如,创建一个这样的文件夹

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

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

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"

如果您正在使用 rails 应用程序并且您的上传位于 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.

这篇关于Rails - Dokku - Paperclip:每次推送到生产中断(404s)用户上传的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆