Complete Lesson 31

main
Simon Quigley 1 year ago
parent cd2f24f7ca
commit 8f470ae322

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

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

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

Loading…
Cancel
Save