1

I am providing the h1 into my header, but I don't want it on products/show. How do I remove it just for that page?

_header.html

<header>
  <h1><%= yield(:heading) %></h1>
</header>

Homepage

<% provide(:heading, 'This is the homepage heading') %>

products/show

<% provide(:heading, '') %>

Obviously, I could just not provide any heading for the products/show page but there is CSS styling applied to my H1 that is screwing up my design, whether there is content in the h1 tag or not.

4

2 回答 2

3

仅在元素有内容时才渲染它:

<header>
  <% if content_for?(:heading) %>
    <h1><%= yield(:heading) %></h1>
  <% end %>
</header>
于 2012-05-29T14:37:34.793 回答
0

Use a different partial? Put an if-ish statement around the header?

As-is the elements themselves will always be there, because there's no reason for them not to be.

于 2012-05-29T14:30:05.517 回答