-
-
Save bbonamin/5399268 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
class FooController < ApplicationController | |
before_filter :user_required! | |
before_filter :admin_required!, :only => [:secret] | |
def not_secret | |
end | |
def secret | |
end | |
end | |
class ApplicationController < ActionController::Base | |
def user_required! | |
raise Exception.new('must be user') if !current_user | |
end | |
def admin_required! | |
raise Exception.new('must be admin') if !current_user.try(:admin?) | |
end | |
def current_user | |
return @current_user if defined?(@current_user) | |
@current_user = User.find(session[:user_id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment