Created
July 15, 2010 14:11
-
-
Save tofumatt/476984 to your computer and use it in GitHub Desktop.
This file contains 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
# Meta-method to setup before_filters on controller | |
# actions requiring various authorization levels. | |
def self.must_be(role, options={}) | |
define_method "#{role}_required" do | |
unless authorized?(role) | |
if logged_in? | |
redirect_to request.referer || root_url, :alert => "You must be an #{role} to access that page." | |
else | |
redirect_to login_path, :alert => "You must be logged in to access that page." | |
end | |
end | |
end | |
protected "#{role}_required" | |
before_filter "#{role}_required".to_sym, options | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment