I''m trying to write a privileging system in Rails and
getting confused with the usage of Module.
Here''s what I want:
#file app/controllers/application.rb
class ApplicationController < ActionController::Base
include PrivilegeSystem
before_filter :check_privilege
end
#file lib/privilege_system.rb
module PrivilegeSystem
def check_privilege
@session[''privileges''].each do |priv|
return true if ???.include?(priv)
end
redirect_to(:controller => ''error'',
:action=>''exceeded'')
end
end
#file app/controllers/some_controller.rb
class SomeController < ApplicationController
privilege_level :hello => [:read, :write],
:some_form => [:write]
def hello
end
def some_form
end
end
-----------------------------------
The problem is where to put the privilege_level
routine and then once I''ve got one, where to store the
data so it can be retrieved at the ??? above.
I tried the following (in both environments.rb and
privilege_system.rb):
module ActionController
module Dependencies
module ClassMethods
def privilege_level(privs)
@@access = privs
end
def get_access_level(action)
@@access || {})[action.to_sym]
end
end
end
end
The data just goes off into the ether. I tried
breakpointing but can''t make any sense of where it''s
at when it''s called.
Help me OB1 Kenobi...
Shawn
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/