我的控制器中到处都是这个:
if not session[:admin]
flash[:notice] = "You don't have the rights to do #{:action}."
redirect_to :action=>:index
return
end
及其兄弟:
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
当我想在一个方法中使用它时,我想把它减少到一个声明行:
def action_which_requires_rights
require_rights :admin
#or:
#:require_rights :user_or_admin
end
显然,如果 require_rights 失败,我不希望执行该方法的其余部分。我发誓有办法做到这一点,但我找不到我在哪里读到它。这是我想象的吗?