Topic: Creating Administration pages by using before_filters

At present I am doing something like this

class ApplicationController < ActionController::Base
  before_filter :create_rbac_user
 
  protected
 
  def create_rbac_user
    @rbac_user = session[:rbac_user]
    #return true if not @rbac_user.nil?
    #return false
    if @rbac_user.nil?
     
    end
    return true
  end

Now what I want to do is create a before_filter so that
if rbac_user.has_role 'Admin' I change the action to be performed to be
admin_<action>.  And of coarse that will then mean that actions like edit, which check whether the user owns that object, will have corresponding admin_edit actions that only the admin can use and which do not do the extra checks.

Is this possible?  If so how can it be done?

Last edited by alistair (2006-08-14 19:40:26)

Re: Creating Administration pages by using before_filters

Oh and another thing.  The site uses ajax very very heavily so this will need to be taken into consideration and be as seamless as possible.

Re: Creating Administration pages by using before_filters

I would think the edit and related admin_edit actions would be very similar. How about just use an if condition to handle the code a little differently in each action depending upon if the user is an admin or not?

Railscasts - Free Ruby on Rails Screencasts

Re: Creating Administration pages by using before_filters

Yeah that is one solution.

I already have a lot of those as there are 3 different member types all with different requirements.  I will see what I can do tho