回形针仅在生产一段时间后显示丢失的文件

Paperclip shows missing files after a while in production only

在开发中,一切正常。我可以将头像、图片和文档上传到帖子,它们会留在那里。

在生产中,在 heroku 中。我可以上传头像、图片和文档。他们工作并出现。但是过了一会儿,它们不再显示,它说 url 不存在。 但是,当我检查数据库时,我可以看到它们存储正确。

这里是我的heroku登录报错:

2020-02-03T10:31:37.916790+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] ActionController::RoutingError (No route matches [GET] "/system/users/avatars/000/000/004/medium/Screenshot_2020-02-01_at_16.06.41.png"):
2020-02-03T10:31:37.916792+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a]
2020-02-03T10:31:37.916795+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
2020-02-03T10:31:37.916797+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2020-02-03T10:31:37.916800+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
2020-02-03T10:31:37.916802+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
2020-02-03T10:31:37.916804+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
2020-02-03T10:31:37.916806+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
2020-02-03T10:31:37.916808+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
2020-02-03T10:31:37.916811+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
2020-02-03T10:31:37.916813+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2020-02-03T10:31:37.916815+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
2020-02-03T10:31:37.916817+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] rack (2.1.2) lib/rack/method_override.rb:24:in `call'
2020-02-03T10:31:37.916819+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] rack (2.1.2) lib/rack/runtime.rb:24:in `call'
2020-02-03T10:31:37.916821+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2020-02-03T10:31:37.916823+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
2020-02-03T10:31:37.916826+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
2020-02-03T10:31:37.916828+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] rack (2.1.2) lib/rack/sendfile.rb:113:in `call'
2020-02-03T10:31:37.916830+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:77:in `call'
2020-02-03T10:31:37.916832+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
2020-02-03T10:31:37.916834+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] puma (4.3.1) lib/puma/configuration.rb:228:in `call'
2020-02-03T10:31:37.916837+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
2020-02-03T10:31:37.916839+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] puma (4.3.1) lib/puma/server.rb:472:in `process_client'
2020-02-03T10:31:37.916841+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] puma (4.3.1) lib/puma/server.rb:328:in `block in run'
2020-02-03T10:31:37.916844+00:00 app[web.1]: [5972883e-916f-43d5-842f-fb4a3898d57a] puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
2020-02-03T10:31:37.919025+00:00 heroku[router]: at=info method=GET path="/system/users/avatars/000/000/004/medium/Screenshot_2020-02-01_at_16.06.41.png?1580721331" host=fierce-spire-88971.herokuapp.com request_id=5972883e-916f-43d5-842f-fb4a3898d57a fwd="90.169.115.213" dyno=web.1 connect=1ms service=3ms status=404 bytes=1902 protocol=https

在production.rb 将此行编辑为 true

config.serve_static_files = true

让我知道这是否适合你:)

问题仅仅是因为我将图像存储在 heroku 上。我没有设置aws。一旦完成,一切都完美无缺。