title: What is the best practice to send data to layout in Rails
body: <p>I am wondering what is the best way to efficiently send data from controller to layout. Normally, I use the layout with yield directive to render the page. So this is my layout</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;%= yield(:title) %&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;%= yield %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the view file</p>
  
  <pre><code>&lt;% content_for :title do %&gt;
      &lt;title&gt;&lt;%= @title %&gt;&lt;/title&gt;
  &lt;% end %&gt;
  
  &lt;section id="page-body"&gt;
     &lt;!-- CONTENT GOES HERE --&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>With this approach, I have to define the @title instance variable in my controller in every method where the @title data is required in its view.</p>
  
  <p>The real problem is that my title and other meta data are stored in the database and because the view uses the same layout file. So I think these data like title and keywords should not be loaded too frequently (At least, not in every method) and content_for should not be declared in every view.</p>
  
  <p>So is there any way for the layout to access these data from the controller directly? without using content_for</p>
  
  <p>Thank you</p>