Skip to content

Commit b12225d

Browse files
committed
Implement controller methods for authenticate or not found
1 parent 0cbb6c4 commit b12225d

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ApplicationController < ActionController::Base
2+
include Erroring
23
include Authentication
34
end

app/controllers/concerns/authentication.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def authenticate_user!
2121
redirect_to new_users_session_path, alert: "You need to sign in to access that page" unless user_signed_in?
2222
end
2323

24+
def authenticate_user_or_not_found!
25+
user_signed_in? || not_found!
26+
end
27+
2428
def redirect_admin_if_authenticated
2529
redirect_to admin_root_path, alert: "You are already logged in." if admin_user_signed_in?
2630
end

app/controllers/concerns/erroring.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Erroring
2+
def not_found!
3+
raise ActionController::RoutingError, "Not Found"
4+
end
5+
end

0 commit comments

Comments
 (0)