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]
“----------------------------”