互いに参照する 2 つのパーシャルがあります。コンソールでネストされた依存関係を計算すると、次のようになります (どのテンプレートがロードされているかを出力するデバッグ コードがいくつかあります)。
finder = ApplicationController.new.lookup_context
ActionView::Digestor.new(name: "posts/show", finder: finder).nested_dependencies
または次のようにrakeタスクを介して:
rake cache_digests:nested_dependencies TEMPLATE=posts/show
最初の依存関係の短いリストを取得し、Ruby スタックがいっぱいになるまでこれを無限ループにします。
...
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
SystemStackError: stack level too deep
(テンプレート名が変更されました)
ただし、アプリ サーバーを実行してテンプレートを要求すると、問題なく実行され、無限ループは発生しません。
上記のすべてのケースでの私の設定は次のとおりです。
config.action_controller.perform_caching = true
config.cache_store = :file_store, Rails.root.to_s + '/tmp/cache/stuff'
ActionView::Base.cache_template_loading = true
このコードは、再帰参照保護があることを示しています: https://github.com/rails/rails/blob/v4.1.8/actionview/lib/action_view/digestor.rb#L35
この保護がサーバー環境では機能するのに、コンソールや rake タスクでは機能しないのはなぜですか?
(これも github の問題https://github.com/rails/rails/issues/18667 )