Ruby on Rails: provide vs content_for

后端 未结 2 1477
自闭症患者
自闭症患者 2021-02-01 03:36

I came across the view helper function \"provide\" today. By looking into its manual I am still confused on how it is different from \"content_for\".

prov

2条回答
  •  無奈伤痛
    2021-02-01 04:15

    Was curious to see what the difference was, and as Thong Kuah pointed to the api, inside the answer:

    This means that, if you have yield :title in your layout and you want to use streaming, you would have to render the whole template (and eventually trigger all queries) before streaming the title and all assets, which kills the purpose of streaming. For this reason Rails 3.1 introduces a new helper called provide that does the same as content_for but tells the layout to stop searching for other entries and continue rendering.

提交回复
热议问题