#MOC #content_for [[🗃️ActionView]]のhelperメソッドとして定義されている。 [[🗃️yield]]を使った位置に、画面語に設定したいコンテンツを差し込むことができる。 ```ruby <html> <head> <%= yield :head %> </head> <body> <%= yield %> </body> </html> # erbでの呼び出し <% content_for :head do %> <title>A simple page</title> <% end %> <p>Hello, Rails!</p> ## 出力 <html> <head> <title>A simple page</title> </head> <body> <p>Hello, Rails!</p> </body> </html> ``` ## 参照 - [レイアウトとレンダリング - Railsガイド](https://railsguides.jp/layouts_and_rendering.html#content-for%E3%82%92%E4%BD%BF%E3%81%86) - [rails/actionview/lib/action_view/helpers/capture_helper.rb at 984c3ef2775781d47efa9f541ce570daa2434a80 · rails/rails · GitHub](https://github.com/rails/rails/blob/984c3ef2775781d47efa9f541ce570daa2434a80/actionview/lib/action_view/helpers/capture_helper.rb#L155)