Skip to content

Commit 048e606

Browse files
author
Ryan Bigg
committed
Section 6.4: Implemented sign out
1 parent f9f6ad0 commit 048e606

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

ticketee/app/controllers/sessions_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ def create
99
render :new
1010
end
1111
end
12+
13+
def destroy
14+
env["warden"].logout
15+
flash[:notice] = "You have signed out."
16+
redirect_to "/"
17+
end
1218
end

ticketee/app/views/layouts/application.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
<li class='<%= 'active' if current_page?('/users/sign_in') %>'>
3131
<%= link_to "Sign in", sign_in_path %>
3232
</li>
33+
<p class="navbar-text navbar-right">
34+
<% if signed_in? %>
35+
Signed in as <%= current_user.email %> &middot;
36+
<%= link_to "Sign out", sign_out_path, method: :delete %>
37+
<% end %>
38+
</p>
3339
</ul>
3440
</div>
3541
</nav>

ticketee/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
post "/users/sign_up", to: "users#create"
1111
get "/sign_in", to: "sessions#new"
1212
post "/sign_in", to: "sessions#create"
13+
delete "/sign_out", to: "sessions#destroy"
1314

1415
resources :projects do
1516
resources :tickets
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "rails_helper"
2+
3+
feature "Signing out" do
4+
let!(:user) { FactoryGirl.create(:user) }
5+
6+
before { login_as(user) }
7+
8+
it "can sign out" do
9+
visit "/"
10+
click_link "Sign out"
11+
expect(page).to have_content("You have signed out.")
12+
end
13+
end

0 commit comments

Comments
 (0)