Hello all.
I'm trying to implement my own role-based access scheme, and I've hit a bit of a snag. It may be that my idea is just plain wrong, and if so, I'd appreciate gentle instruction as to how to make it more sound.
My intent is to do something like
class MyController < ApplicationController permit_access(:admin) permit_access(:normal_user, :only => [:this, :that])
before_filter :require_access
def this end
def that end
def the_other end
private
def require_access redirect_to error_path unless verify_access(@current_user) end end
The point of this endeavor is to more easily allow multiple roles to the same action. To that end, I created a module called RoleAccess that defines a permit_access method and a verify_access method. The idea is that I'd have a hash of controllers, actions, and roles that would be populated by permit_access and inspected by verify_access. The problem is that permit_access is a class method and verify_access is an instance method, so my module looks like
module RoleAccess module ClassMethods def permit_access end end
module InstanceMethods def verify_access end end end
and I can't figure out how to have a hash shared between ClassMethods::permit_access and InstanceMethods::verify_access. First, can this be done? If so, will someone please point me to some sample code that illustrates how to do it. I've been looking through various pieces of Rails source and scouring the internet, which has brought me to the point where I am, but I can't quite get over the hump.
Peace, Phillip