Created
May 8, 2013 15:59
-
-
Save jesjos/5541466 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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