Rails heroku 上的 5 忘记了用回形针和 turbolinks 存储的文件:没有路由匹配

Rails 5 on heroku forgets files stored with paperclip and turbolinks: No route matches

我有一个博客,文件 up-/download 通过回形针 5.1.0 和 turbolinks 5.0.1。未经验证的上传现在可以正常工作,但下载仅在上传后的短时间内有效。之后显示错误 (404):

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

这没有帮助:

heroku rake db:migrate
heroku restart

我在 heroku 上使用 mysql DB 进行生产。当我不通过 h​​eroku 部署时:然后本地副本在 ruby 版本 2.2.4!

下工作得很好

使用 git push heroku master 在 heroku 上进行的新部署未修复附件链接。

只有手动删除 DB 文件并重新上传才能使附件链接在短时间内再次有效。

P。 S. 当测功机重新启动时,e。 G。使用 heroku restart,则文件系统是新的并已删除。但我不知道,如何使用 redis 或 amazon aws s3 使文件系统持久化!

日志说:

2017-01-31T12:21:03.027810+00:00 heroku[路由器]: at=info method=GET path="/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar" 主机=无限针叶林-25466.herokuapp.com request_id=fb775bcc-64f4-4d6b-89c0-70991af31e2f fwd="178.15.12.47" dyno=web.1 connect=0ms service=2ms status=404 bytes=1744 2017-01-31T12:21:03.026812+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] 开始获取“/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar " 178.15.12.47 在 2017-01-31 12:21:03 +0000 2017-01-31T12:21:03.027262+00:00 应用[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] 2017-01-31T12:21:03.027284+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] ActionController::RoutingError (没有路由匹配 [GET] "/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar"): 2017-01-31T12:21:03.027302+00:00 应用[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] 2017-01-31T12:21:03.027334+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.1/ lib/action_dispatch/middleware/debug_exceptions.rb:53:在 call' 2017-01-31T12:21:03.027336+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/show_exceptions.rb:31:incall' 2017-01-31T12:21:03.027337+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/railties-5.0.1/ lib/rails/rack/logger.rb:36:in call_app' 2017-01-31T12:21:03.027338+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in呼叫阻塞' 2017-01-31T12:21:03.027339+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.1/ lib/active_support/tagged_logging.rb:26:in tagged' 2017-01-31T12:21:03.027338+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.1/lib/active_support/tagged_logging.rb:69:in块中标记' 2017-01-31T12:21:03.027340+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.1/ lib/active_support/tagged_logging.rb:69:在 tagged' 2017-01-31T12:21:03.027341+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:incall' 2017-01-31T12:21:03.027341+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.1/ lib/action_dispatch/middleware/request_id.rb:24:in call' 2017-01-31T12:21:03.027342+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/method_override.rb:22:incall' 2017-01-31T12:21:03.027343+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/ lib/rack/runtime.rb:22:在 call' 2017-01-31T12:21:03.027344+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:incall' 2017-01-31T12:21:03.027345+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.1/ lib/action_dispatch/middleware/executor.rb:12:in call' 2017-01-31T12:21:03.027346+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/static.rb:136:incall' 2017-01-31T12:21:03.027346+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/ lib/rack/sendfile.rb:111:in call' 2017-01-31T12:21:03.027347+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/railties-5.0.1/lib/rails/engine.rb:522:incall' 2017-01-31T12:21:03.027349+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/ lib/puma/server.rb:578:in handle_request' 2017-01-31T12:21:03.027349+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/lib/puma/server.rb:415:inprocess_client' 2017-01-31T12:21:03.027350+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/ lib/puma/server.rb:275:in block in run' 2017-01-31T12:21:03.027351+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/lib/puma/thread_pool.rb:120:incall' 2017-01-31T12:21:03.027352+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/ lib/puma/thread_pool.rb:120:in block in spawn_thread' 2017-01-31T12:21:03.027348+00:00 app[web.1]: [fb775bcc-64f4-4d6b-89c0-70991af31e2f] vendor/bundle/ruby/2.2.0/gems/puma-3.7.0/lib/puma/configuration.rb:226:incall'

C:\Sites\blog_production_heroku>

这是根本原因: 当 dyno 定期或使用 heroku restart 重新启动时,文件系统将被初始化和更新。

我仍在努力将 Amazon S3 持久性添加到我的应用程序中...

回形针 gem 的新 git 版本现在可以与 aws-sdk-s3 gem 一起使用,将其添加到 Gemfile:

#Paperclip
gem 'paperclip', git: 'git://github.com/thoughtbot/paperclip.git'