Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Applying before_action to entire namespace sample
# 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
You can’t perform that action at this time.