开发者

has_permission_on with Declarative Authorization, non attribute condition

开发者 https://www.devze.com 2023-03-15 18:32 出处:网络
I want to give authorization to a开发者_JS百科 specific action if a session variable is set in my app. I can\'t figure out how to do this. Something like:

I want to give authorization to a开发者_JS百科 specific action if a session variable is set in my app. I can't figure out how to do this. Something like:

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

I don't understand how to accomplish this basic task. Any help appreciated.


You want to use a before_filter on the function e.g.

before_filter :authorize, :only => :action

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

精彩评论

暂无评论...
验证码 换一张
取 消