Rails - override <head> page element when using a partial or a specific controller view

后端 未结 1 469
失恋的感觉
失恋的感觉 2020-12-30 10:59

Is there a way to append or override the page element inside a rails view?

Suppose I have something I only want to include in a particular

相关标签:
1条回答
  • 2020-12-30 11:25

    In your application.html.erb:

    <head>
      <% if content_for? :for_head %>
        <%= yield :for_head %>
      <% end %>
    </head>
    

    In your "specific" view:

    <% content_for :for_head do %>
      Something-to-put-in-head
    <% end %>
    

    :for_head isn't predefined: naming it is up to you. It could be anything.

    0 讨论(0)
提交回复
热议问题