Nil error in _save_fragment when I attempt to cache an action that uses send_file
Environment
- Windows 10
- ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]
- Rails 5.0.6
- actionpack-action_caching 1.2.0
Description
When I attempt to use caches_action on an action that sends a file using send_file I get the following nil error:
undefined method `each' for nil:NilClass
actionpack-action_caching (1.2.0) lib/action_controller/caching/actions.rb:122:in `_save_fragment'
actionpack-action_caching (1.2.0) lib/action_controller/caching/actions.rb:165:in `around'
activesupport (5.0.6) lib/active_support/callbacks.rb:405:in `public_send'
...
Repro
I pushed an app that demonstrates the crash here. The first commit is a clean app after rails new. Subsequent commits add the working controller action then introduce caching to reproduce the crash.
Receiving the same error with send_file.
My environment:
- macOS 10.14
- ruby 2.5.3
- rails 5.2.2
- actionpack-action_caching 1.2.0
This worked perfectly fine with:
- ruby 2.2.8
- rails 4.2.x
That said, despite the need for a gem/library like this one, the community doesn't seem to have much support behind this and would rather use header tags for most caching needs. Unfortunately, I see this issue was posted 9 months ago and was never addressed. The problem is this gem no longer solves caching files that will never change and should be cached with a store that is faster than some CDN. There are alternatives, but not when you're using Heroku (or any server with an ephemeral file system) and not without unnecessary complexity.