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.
使用Dokku在Digital Ocean上运行Rails 4应用程序。用户可以通过回形针上传图像。我可以上传图像,应用程序运行良好并显示所有图像。一旦我做了一个像文本更改的小改动,我运行$ git push dokku master,所有上传的图像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_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
Any help will be greatly appreciated!
任何帮助将不胜感激!
2 个解决方案
#1
2
You can create a docker option to have it like persistent storage without a plugin. or example, create a folder like this
您可以创建一个docker选项,使其像没有插件的持久存储一样。或者,例如,创建一个这样的文件夹
mkdir FOLDER_NAME
then you can add a docker option like this
然后你可以像这样添加一个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"
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应用程序并且你的上传是app / public / uploads,如果没有,只需将该文件夹更改为上传文件的位置即可。
#2
6
Dokku act as heroku. You should use s3 or any storage service for uploaded image.
Dokku充当了heroku。您应该为上传的图像使用s3或任何存储服务。
Or you can add persitent storage and mount to your dokku container app http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/
或者您可以添加persitent存储并安装到您的dokku容器应用程序http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/
#1
2
You can create a docker option to have it like persistent storage without a plugin. or example, create a folder like this
您可以创建一个docker选项,使其像没有插件的持久存储一样。或者,例如,创建一个这样的文件夹
mkdir FOLDER_NAME
then you can add a docker option like this
然后你可以像这样添加一个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"
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应用程序并且你的上传是app / public / uploads,如果没有,只需将该文件夹更改为上传文件的位置即可。
#2
6
Dokku act as heroku. You should use s3 or any storage service for uploaded image.
Dokku充当了heroku。您应该为上传的图像使用s3或任何存储服务。
Or you can add persitent storage and mount to your dokku container app http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/
或者您可以添加persitent存储并安装到您的dokku容器应用程序http://dokku.viewdocs.io/dokku/advanced-usage/persistent-storage/