Complete Lesson 31

main
Simon Quigley 1 year ago
parent cd2f24f7ca
commit 8f470ae322

@ -11,6 +11,7 @@ class UsersController < ApplicationController
def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
redirect_to @user, notice: "Thanks for signing up!"
else
render :new, status: :unprocessable_entity

@ -1,2 +1,5 @@
module ApplicationHelper
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end

@ -13,12 +13,18 @@
</li>
</ul>
<ul class="navbar-nav">
<% if current_user %>
<li class="nav-item">
<%= link_to current_user.name, current_user %>
</li>
<% else %>
<li class="nav-item">
<%= link_to "Sign In", new_session_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to "Sign Up", signup_path, class: "nav-link" %>
</li>
<% end %>
</ul>
</div>
</nav>

Loading…
Cancel
Save