Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bbonamin/5399268 to your computer and use it in GitHub Desktop.
Save bbonamin/5399268 to your computer and use it in GitHub Desktop.
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