title: Display a string variable in view and change it when a view is rendered
body: <p>I am trying to store a variable which will be changed when a view is rendered. It's a text in my header which tells me what page I am on (Home, register, login, etc). Here's an example:</p>
  
  <p>Home (root of the website):</p>
  
  <p><a href="https://i.stack.imgur.com/YlXmi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YlXmi.png" alt="enter image description here"></a></p>
  
  <p>Register (/authentication/register)</p>
  
  <p><a href="https://i.stack.imgur.com/PdPhV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PdPhV.png" alt="enter image description here"></a></p>
  
  <p>I tried storing the variable in my base (root) view with <code>&lt;%= $header_title = "AppName" %&gt;</code> Like this:</p>
  
  <p>My code (application.html.erb): </p>
  
  <pre><code>&lt;%= $header_title = "AppName" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;%= t('app') %&gt;&lt;/title&gt;
    &lt;%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' =&gt; true %&gt;
    &lt;%= javascript_include_tag 'application', 'data-turbolinks-track' =&gt; true %&gt;
    &lt;%= csrf_meta_tags %&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;header&gt;
          &lt;%= render 'layouts/header.html.erb'%&gt;
      &lt;/header&gt;
  
  &lt;main&gt;
      &lt;%= yield %&gt;
  &lt;/main&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But when I do this, this happens to the document (<code>AppName</code> is just a placeholder):</p>
  
  <p><a href="https://i.stack.imgur.com/Fl73R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fl73R.png" alt="enter image description here"></a></p>
  
  <p>I don't want it to put the string above the header in the document like that, instead I am just trying to store that variable and then use it in the header text.</p>
  
  <p>Here's the "layouts/_header.html.erb"</p>
  
  <pre><code>&lt;div id="header-body"&gt;
  &lt;div id="title-body" class="header-item-padding"&gt;
      &lt;p&gt;&lt;%= $header_title %&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id="navigation-body" class="header-item-padding"&gt;
  
  &lt;%= isloggedin = false
      if isloggedin == false
          render 'layouts/header/navigationRegister.html.erb'
      else
          if userIsAdmin = false
              render 'layouts/header/navigationUser.html.erb'
          else
              render 'layouts/header/navigationAdmin.html.erb'
          end
      end %&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>