Фиксим No such middleware to insert before: ActionDispatch::Static

Запуская локально прекомпиляцию ассетов в production режиме я получил следующую ошибку:

No such middleware to insert before: ActionDispatch::Static
/../../.rvm/gems/[email protected]/gems/actionpack-5.1.3/lib/action_dispatch/middleware/stack.rb:106:in `assert_index'
/../../.rvm/gems/[email protected]/gems/actionpack-5.1.3/lib/action_dispatch/middleware/stack.rb:73:in `insert'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/configuration.rb:69:in `block in merge_into'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/configuration.rb:68:in `each'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/configuration.rb:68:in `merge_into'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/engine.rb:507:in `block in app'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/engine.rb:504:in `synchronize'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/engine.rb:504:in `app'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/application/finisher.rb:45:in `block in <module:Finisher>'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/initializable.rb:30:in `instance_exec'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/initializable.rb:30:in `run'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/initializable.rb:59:in `block in run_initializers'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/initializable.rb:58:in `run_initializers'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/application.rb:353:in `initialize!'
/../../dev/web/project/config/environment.rb:5:in `<top (required)>'
/../../.rvm/gems/[email protected]/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
/../../.rvm/gems/[email protected]/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `block in require'
/../../.rvm/gems/[email protected]/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:258:in `load_dependency'
/../../.rvm/gems/[email protected]/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in `require'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/application.rb:329:in `require_environment!'
/../../.rvm/gems/[email protected]/gems/railties-5.1.3/lib/rails/application.rb:445:in `block in run_tasks_blocks'
/../../.rvm/gems/[email protected]/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/../../.rvm/gems/[email protected]/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/../../.rvm/gems/[email protected]/bin/ruby_executable_hooks:24:in `eval'
/../../.rvm/gems/[email protected]/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)

Чтобы пофиксить ее, нужно настроить config.public_file_server.enabled:

environments/production.rb
config.public_file_server.enabled = true # делаем true
но лучший вариант использовать ENV'ы (код из RoR 5):
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
соответственно:
RAILS_SERVE_STATIC_FILES=true
Альтернативный способ - использование библиотеки rails_12factor, которая дает больше гибкости в работе с ассетами. У нее в зависимостях rails_serve_static_assets, который в свою очередь добавляет значение true в конфиги ассетов. Поэтому используя эти библиотеки не обязательно самим править файл конфига или добавлять новый ENV.