Skip to content

Instantly share code, notes, and snippets.

@bufordtaylor
Created November 18, 2015 19:37
Show Gist options
  • Save bufordtaylor/b11a22d6986f9a9d81c7 to your computer and use it in GitHub Desktop.
Save bufordtaylor/b11a22d6986f9a9d81c7 to your computer and use it in GitHub Desktop.
# in routes
namespace :admin do
resources :sample, only: :index
end
# app/controllers/admin/sample_controller.rb
class Admin::SampleController < ApplicationController
before_filter :authorize_admin
def index
# do shit
end
end
# in app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
#... other shit above
#...
def authorize_admin
redirect_to root_url unless current_user and current_user.admin?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment