Skip to content

Instantly share code, notes, and snippets.

@lennartkoopmann
Created March 5, 2009 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennartkoopmann/74290 to your computer and use it in GitHub Desktop.
Save lennartkoopmann/74290 to your computer and use it in GitHub Desktop.
def permission?
user = current_user
controller = params[:controller]
action = params[:action]
id = params[:id]
# Okay, the user is an administrator. Allow all access.
return true if user.admin
# Fine grained access rules.
# Allow changing own profile.
return true if controller == "users" and (action == "edit" or action == "update") and id == user.id.to_s
# User is no admin and no access rule allowed access.
flash[:error] = "Sorry. You must be an administrator to perform this action."
redirect_back_or_default('/')
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment