I have this showing up all over in my controllers:
if not session[:admin]
flash[:notice] = "You don't have the rights to do #{:action}."
redirect_to :action=>:index
return
end
And its sibling:
if not session[:user] and not session[:admin]
flash[:notice] = "You don't have the rights to do #{:action}."
redirect_to :action=>:index
return
end
I would like to reduce this all down to a single declarative line when I want to use it in a method:
def action_which_requires_rights
require_rights :admin
#or:
#:require_rights :user_or_admin
end
Clearly, if require_rights fails, I don't want the rest of the method executed. I would swear that there was a way to do this, but I can't find where I read about it. Am I imagining this?