In the nav bar, paste the following to create sign in/sign out functionality:
<ul class="navbar-nav">
<% if user_signed_in? %>
<li class="nav-item">
<%= link_to "Edit profile", edit_user_registration_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Sign out", destroy_user_session_path, class: "nav-link", method: :delete %>
</li>
<% else %>
<li class="nav-item">
<%= link_to "Sign in", new_user_session_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Sign up", new_user_registration_path, class: "nav-link" %>
</li>
<% end %>
</ul>
To enforce sign in/out, we add a before action in ApplicationController:
- Add: "before_action :authenticate_user!"
Top comments (0)