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

て烟熏妆下的殇ゞ 提交于 2019-12-04 06:26:09

问题


I have a blog with file up-/download via paperclip 5.1.0 and turbolinks 5.0.1. Upload without validation works fine now, but download is only working for a short period after upload. Afterwards an error (404) is displayed:

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.

This did not help:

heroku rake db:migrate
heroku restart

I am on production with mysql DB on heroku. When I am not deploying via heroku: then the local copy works just fine with ruby version 2.2.4!

New deployment on heroku with git push heroku master does not fix the attachment links.

Only manual deletion of DB files and new upload makes attachment links work again for a short period of time.

P. S. When the dyno is restartet, e. g. with heroku restart, then the filesystem is new and deleted. But I do not know, how to make filesystem persistent with redis or amazon aws s3!

The log says:

2017-01-31T12:21:03.027810+00:00 heroku[router]: at=info method=GET path="/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar" host=infinite-taiga-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] Started GET "/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar" for 178.15.12.47 at 2017-01-31 12:21:03 +0000 2017-01-31T12:21:03.027262+00:00 app[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 (No route matches [GET] "/system/articles/attachments/000/000/015/original/gmr-1.8.3.jar"): 2017-01-31T12:21:03.027302+00:00 app[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:in 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:inblock in call' 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:inblock in tagged' 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:in 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:in 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>


回答1:


This is the root cause: When the dyno is restartet periodically or with heroku restart then the filesystem is initialised and new.

I am still struggling to add Amazon S3 persistence to my app...




回答2:


New git version of paperclip gem now works with aws-sdk-s3 gem, add this to Gemfile:

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


来源:https://stackoverflow.com/questions/41957664/rails-5-on-heroku-forgets-files-stored-with-paperclip-and-turbolinks-no-route-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!