Skip to content

Instantly share code, notes, and snippets.

@patoui
Created December 8, 2018 17:17
Show Gist options
  • Save patoui/f66cf5dbcd250108a0671433b43e22e8 to your computer and use it in GitHub Desktop.
Save patoui/f66cf5dbcd250108a0671433b43e22e8 to your computer and use it in GitHub Desktop.
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