ruby on rails - Nested Layout not rendering properly -


i have application.html.erb, has this:

<!-- truncated brevity --> <body>    <%= content_for?(:content) ? yield(:content) : yield %> </body> 

then have layout family_tree.html.erb

that looks this:

<%= render template: "layouts/application" %>  <main id="view">    <title>timeline!</title>    <%= render partial: "tree_header" %>    <% content_for :content %>     <%= yield %>   <% end %>  </main> 

that partial _tree_header.html.erb looks this:

<header class="profile-header">    <div class="wrapper">      <div class="profile-author">       <h2 class="center author-name">martha doe <a class="author-description-btn" href=""><i class="icon-list-2"></i></a></h2>       <h4 class="author-title">aunt <i class="author-title-circ"></i><i class="author-title-circ"></i><i class="author-title-circ"></i></h4>       <!-- <div class="author-description">         <p>nullam quis risus eget urna mollis ornare vel eu leo. etiam porta sem malesuada magna mollis euismod.</p>       </div> -->     </div>      <nav class="profile-nav center">       <ul>         <li><%= link_to "timeline", timeline_path %></li>         <li class="active"><a href="#">family tree</a></li>       </ul>     </nav>   </div> </header> 

this how want render (this static html):

static html layout

but how renders:

nested layout render

notice though specified render partial: "tree_header" before yield statement within content_for block, still seems rendering after yield within layouts/family_tree.html.erb.

how solve this?

edit 1

using amihule's answer have more or less solved it, seeing space between top , tree_header partial. content_for block causing space?

space in header

tl;dr: move <%= render template: "layouts/application" %> bottom of sub-layout , include else in content_for block.

<% content_for :content %>   <main id="view">     <title>timeline!</title>     <%= render partial: "tree_header" %>     <%= yield %>   </main> <% end %> <%= render template: "layouts/application" %> 

you want fill content :content first , render template include this. way have template set up, notice on rails console renders layouts/application before partial, this:

rendered test/foo.html.erb within layouts/family_tree rendered layouts/application.html.erb rendered test/_tree_header.html.erb 

see using nested layouts.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -