'heroku restart' 后坚持大礼包产品图片

Persist spree product pictures after 'heroku restart'

我有一个正在处理的示例页面:

http://os-oven.herokuapp.com/

我从哪里开始上传产品图片的。在我尝试的某个时刻,我不得不运行

heroku restart

这把我的照片擦掉了:

2015-01-08T14:13:39.161552+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/spree/products/1/small/Pumpkin_Pie_from_a_-real-_pumpkin__November_2007.jpg"):
2015-01-08T14:13:39.161554+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2015-01-08T14:13:39.161555+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2015-01-08T14:13:39.161573+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/rack/logger.rb:38:in `call_app'
2015-01-08T14:13:39.161574+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/rack/logger.rb:20:in `block in call'
2015-01-08T14:13:39.161576+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2015-01-08T14:13:39.161578+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/tagged_logging.rb:26:in `tagged'
2015-01-08T14:13:39.161579+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/tagged_logging.rb:68:in `tagged'
2015-01-08T14:13:39.161581+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/rack/logger.rb:20:in `call'
2015-01-08T14:13:39.161582+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2015-01-08T14:13:39.161584+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2015-01-08T14:13:39.161585+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2015-01-08T14:13:39.161586+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
2015-01-08T14:13:39.161588+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/static.rb:84:in `call'
2015-01-08T14:13:39.161590+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2015-01-08T14:13:39.161591+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:514:in `call'
2015-01-08T14:13:39.161593+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:144:in `call'
2015-01-08T14:13:39.161594+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:576:in `process_client'
2015-01-08T14:13:39.161596+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670:in `worker_loop'
2015-01-08T14:13:39.161597+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
2015-01-08T14:13:39.161598+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start'
2015-01-08T14:13:39.161600+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
2015-01-08T14:13:39.161601+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'
2015-01-08T14:13:39.161602+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'

图片一定是保存在本地的,当我重新启动我的应用程序时,它从git中提取了最新的代码。

如何将大礼包的产品图片持久化到数据库中?

我的想法:

  1. 将它们放在 s3 之类的东西中。不利的是我现在宁愿有一个 'free-er' 选项。另外,你会如何配置 spree 来做到这一点?
  2. 获取版本控制中的文件。这可能有效,除非我需要 prod 和 dev 使用相同的数据库和存储在数据库中的相同文件路径。
  3. 将 blob 保存到数据库。我知道这可能不是最有效的方法,但数据始终可用。仍然需要调整狂欢引擎才能做到这一点。

您无法在 heroku 上保存图片。 Heroku 有 "Read-only Filesystem" https://devcenter.heroku.com/articles/read-only-filesystem

您可以免费使用 cloudinary.com 或 Amazon S3 Amazon S3 还免费提供高达 5Gb 的空间。 http://aws.amazon.com/free/