Rails Layout Rendering with a controller condition

I do not know how best to do this.

On my application.html.erb, I define a div header.

My default controller (root) is the home controller. And I wish that if I am in the index of the main page, the heading is a rendering with some content, but all other controllers display different content inside this heading.

How can I create a condition in this div header to render various content based on the displayed controller?

+3
source share
1 answer

content_for , , .

application.html.erb

<div id="header">
  <%= yield :header %>
</div>

:

<% content_for :header do %>
  This is a controller-specific header.
<% end %>

, , , ..

+6

Source: https://habr.com/ru/post/1740147/


All Articles