In Rails we can use partials to organize our code in the layouts . This is generally helpful when we have layouts running up to hundreds of lines. For example we have a top nav bar which looks different for logged in and non logged in user. Then we can write the code for top nav bar in two different partial and render them in the layout. For example:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<header>
<% if user_logged_in? %>
<%= render 'layouts/logged_in_header' %>
<% else %>
<%= render 'layouts/non_logged_in_header' %>
<% end %>
</header>
</body>
</html>
0 Comment(s)