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
精彩评论