Skip to content

Instantly share code, notes, and snippets.

@jesjos
Created May 8, 2013 15:59
Show Gist options
  • Save jesjos/5541466 to your computer and use it in GitHub Desktop.
Save jesjos/5541466 to your computer and use it in GitHub Desktop.
# config/routes.rb
namespace :admin do
resources :boats
resources :stuff
end
# app/controllers/admin_controller.rb
# This controller just refactors all shared logic for admin-namespaced controllers
class AdminController < ApplicationController
# If multiple models:
before_filter :authenticate_admin!
# If admin flag:
before_filter :check_user_is_admin
def check_user_is_admin
unless current_user.admin?
redirect_to root_path, notice: t("notices.action_not_allowed")
end
end
end
# app/controllers/admin/boats_controller.rb
# Make sure all admin-namespaced controllers inherit from the AdminController
class BoatsController < AdminController
respond_to :html
def index
@boats = Boat.all
respond_With @boats
end
# ... and whatever you may want... #
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment