Created
December 8, 2018 17:17
-
-
Save patoui/f66cf5dbcd250108a0671433b43e22e8 to your computer and use it in GitHub Desktop.
Applying before_action to entire namespace sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
namespace :admin do | |
get 'dashboard' => 'dashboard#index' | |
end | |
# app/controllers/admin/admin_controller.rb | |
include SessionsHelper | |
class Admin::AdminController < ApplicationController | |
http_basic_authenticate_with name: "johndoe", password: "secret" | |
before_action :require_login | |
private | |
def require_login | |
unless logged_in? | |
redirect_to '/login' | |
end | |
end | |
end | |
# app/controllers/admin/dashboard_controller.rb | |
class Admin::DashboardController < Admin::AdminController | |
def index | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment