has_permission_on with Declarative Authorization,非属性条件

时间:2011-06-28 13:54:13

标签: ruby-on-rails declarative-authorization

如果在我的应用中设置了会话变量,我想授予特定操作的权限。我无法弄清楚如何做到这一点。类似的东西:

has_permission_on :admin, :to => :action do
  true if session[:key]
end

我不明白如何完成这项基本任务。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

你想在函数上使用before_filter,例如

before_filter :authorize, :only => :action

private
def authorize
unless session[:key]
flash[:notice] = "Cannot do this"
redirect_to(:controller => "controller", :action => "otheraction")
end