0

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!

2 Answers 2

7

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/

3

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.

1
  • dokku docker-options:add APP_NAME deploy "-v /home/dokku/FOLDER_NAME:/app/public/uploads" Thats what I was missing....sorry for getting back so late.
    – jb_9122
    Dec 8, 2016 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.