Problem with discovering available controllers through refle

This code works under webrick to load and identify every controller in a
rails
app. However, it fails under mongrel. Instead it only identifies the
controller that actually called the method.

Does anyone understand why?

Thanks in advance,
David J.
NW Arkansas


code snip:

def MyModel.synchronize_with_controllers
# Load all the controller files
Find.find( RAILS_ROOT + ‘/app/controllers’ ) do |file_name|

  if /_controller.rb$/ =~ file_name
    if (@@debuglevel >= 4)
      p "Loading "+file_name
    end
    begin
      load file_name
    rescue
      logger.error("Unable to load file #{file_name}")
    end;
  end
end

all_controllers = ObjectSpace.subclasses_of( ApplicationController )

if (@@debuglevel >= 4)
  p '----------------------------'
  p "all_controllers:"
  p all_controllers;
  p '----------------------------'
end

Log from Mongrel (what’s up?):

“Loading script/…/config/…/app/controllers/first_controller.rb”
“Loading script/…/config/…/app/controllers/second_controller.rb”
“Loading script/…/config/…/app/controllers/third_controller.rb”
“Loading script/…/config/…/app/controllers/fourth_controller.rb”
“Loading script/…/config/…/app/controllers/this_controller.rb”
“Loading script/…/config/…/app/controllers/fifth_controller.rb”
“Loading script/…/config/…/app/controllers/sixth_controller.rb”
“Loading script/…/config/…/app/controllers/seventh_controller.rb”
“Loading script/…/config/…/app/controllers/eighth_controller.rb”
“----------------------------”
“all_controllers:”
[ThisController]
“----------------------------”


Log from Webrick (expected behavior):

“Loading script/…/config/…/app/controllers/first_controller.rb”
“Loading script/…/config/…/app/controllers/second_controller.rb”
“Loading script/…/config/…/app/controllers/third_controller.rb”
“Loading script/…/config/…/app/controllers/fourth_controller.rb”
“Loading script/…/config/…/app/controllers/this_controller.rb”
“Loading script/…/config/…/app/controllers/fifth_controller.rb”
“Loading script/…/config/…/app/controllers/sixth_controller.rb”
“Loading script/…/config/…/app/controllers/seventh_controller.rb”
“Loading script/…/config/…/app/controllers/eighth_controller.rb”
“----------------------------”
“all_controllers:”
[FirstController,SecondController,ThirdController,FourthController,ThisController,FifthController,SixthController,SeventhController,EighthController]
“----------------------------”

Hi –

On Thu, 5 Jul 2007, David J. wrote:

This code works under webrick to load and identify every controller in a rails
app. However, it fails under mongrel. Instead it only identifies the
controller that actually called the method.

I’m afraid I can only give you the unhelpful report that it worked OK
under Mongrel when I ran it.

David

I’m running mongrel 1.0.1, ruby 1.8.4, rails 1.2.3 on gentoo and
ubuntu (feisty) linux.

What platform are you running on?

On Jul 5, 5:12 pm, David J. [email protected] wrote:

This code works under webrick to load and identify every controller in a rails
app. However, it fails under mongrel. Instead it only identifies the
controller that actually called the method.

Does anyone understand why?

how about Dir.glob e.g.

http://destiney.com/blog/rubyonrails-model-controller-lists

Mac Tiger, Ruby 1.8.6, Rails 1.2.3, Mongrel 1.0.1.

I bet an update to Ruby 1.8.6 is in order.

Thanks!

Hi –

On Thu, 5 Jul 2007, [email protected] wrote:

I’m running mongrel 1.0.1, ruby 1.8.4, rails 1.2.3 on gentoo and
ubuntu (feisty) linux.

What platform are you running on?

Mac Tiger, Ruby 1.8.6, Rails 1.2.3, Mongrel 1.0.1.

David