Before_filter get name of controller


#1

Hi,

I have written a before_filter to check if a person is authorized to
access parts of a controller like so:

def check_authorized_ads
@rights = Right.find_by_user_id(1)
unless @rights.ads
flash[:notice] = “You are not authorized.”
redirect_to(:controller => “user”, :action => “login”)
end

In my rights table I have a column for each controller, indicating if a
user is authorized or not. The easiest way is to write a new
before_filter for each controller, like:

def check_authorized_controllerx
@rights = Right.find_by_user_id(1)
unless @rights.controllerx
flash[:notice] = “You are not authorized.”
redirect_to(:controller => “user”, :action => “login”)
end

But that is not according to the DRY principles. Is their a way to pass
the name of the controller or another param with the before_filter?
Thanks.

Kind regards,

Nick