Here is the _header.html.erb
of our Rails 4 app, made with Bootstrap 3 components:
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<nav>
<div class="col-xs-4">
<%= link_to "APP NAME", root_path, id: "logo" %>
</div>
<div class="col-xs-4 text-center">
<ul class="nav navbar-nav navbar-center">
<li><%= link_to "Features", features_path %></li>
<li><%= link_to "Pricing", pricing_path %></li>
<li><%= link_to "Blog", '#' %></li>
</ul>
</div>
<div class="col-xs-4">
<ul class="nav navbar-nav navbar-right">
<% if current_user.try(:admin?) %>
<li><%= link_to "Users", users_path %></li>
<% end %>
<% if logged_in? %>
<li><%= link_to "Dashboard", current_user %></li>
<li><%= link_to "Settings", current_user %></li>
<li><%= link_to "Log out", logout_path, method: "delete" %></li>
<% else %>
<li><%= link_to "Log in", login_path %></li>
<li><%= link_to "Sign up", signup_path %></li>
<% end %>
</ul>
</div>
</nav>
</div>
</header>
As you can see, this conditionally displays a navigation bar, depending on whether the current user is logged out, logged in or logged in as admin.
However, we are wondering how we could display a different navigation bar on different pages.
For instance, on all public pages (home, features, pricing, blog, help, etc.), we would like to display the Features
, Pricing
& Blog
links (whether the user is logged in or not) but on the inner pages of the app (dashboard, settings, etc) we would like to remove these links.
EDIT: to make things clearer, what we call the public pages are actually our static_pages
, which rely on our StaticPages#Controller
, while the inner app pages such as dashboard and settings rely on our Users#Controller
.
How can we achieve this? Do we need to create a new _header.html.erb
partial?
Is there a particular Rails way to do that?