UserEngine -- Permission.synchronize_with_controllers -- tro

I suspect there’s an easier version of this question that I could ask,
but I’m not sure where I’m going wrong. I have LoginEngine and
UserEngine setup and seemingly running fine. However, not all of my
controllers are being found when I run “rake sync_permissions”.
Specifically, it’s the controllers that are not in the base
controllers folder, but rather in a subfolder. I have my admin
controllers separated in their own “admin” directory directly under
the normal controllers directory.

I’ve stepped through the Permission.synchronize_with_controllers
method with the console to try to figure out what’s going on.

This line does pick up all of my controllers.

controller_files = Dir[RAILS_ROOT + 

“/app/controllers/**/*_controller.rb”]

But then this line doesn’t include any of my admin controllers.

ApplicationController.all_controllers.collect do |controller|

If I understand this correctly, ApplicationController is an instance
of my application.rb file in the controllers directory. Yes? Is
there something that I need to do so that it’s aware of controllers in
the subdirectories?

/app/controllers/application.rb

require ‘login_engine’
class ApplicationController < ActionController::Base
include LoginEngine
include UserEngine

helper :user
model :user

before_filter :authorize_action

end

Example of one of my admin controllers.

class Admin::PlayersController < ApplicationController
layout “admin_layout”

#… methods here (I have several methods defined here, but figured
no one really cared to see them all …

end

– James

This is a known problem; basically the methods we were using in Rails
to get all subclasses don’t return any classes defined within any
modules (see a recent post by Tom W. on the Rails-core list about
this).

We should have a fixed version out very soon, but you can see the
change in the UserEngine trunk currently (in the authorized_system.rb
file, ‘all_controllers’ method):

http://opensvn.csie.org/rails_engines/user_engine/trunk/lib/user_engine/authorized_system.rb

  • james

On 1/25/06, James A. [email protected] wrote:

This is a known problem; basically the methods we were using in Rails
to get all subclasses don’t return any classes defined within any
modules (see a recent post by Tom W. on the Rails-core list about
this).

We should have a fixed version out very soon, but you can see the
change in the UserEngine trunk currently (in the authorized_system.rb
file, ‘all_controllers’ method):

That sounds great. I ended up just moving my controllers out of their
modules and into the base controller directory. No big deal, really,
but it’s good to know that this will be supported in the future.

Thanks!

– James