# Problem with discovering available controllers through refle

**URL:** <https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691>\
**Category:** Rails\
**Created:** [July 6, 2007, 2:13am UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691 "2007-07-06T02:13:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 6, 2007, 2:13am UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/1 "2007-07-06T02:13:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 6, 2007, 2:47am UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/2 "2007-07-06T02:47:49Z")

</div>

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

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 6, 2007, 5:03am UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/3 "2007-07-06T05:03:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 6, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/4 "2007-07-06T15:47:37Z")

</div>

On Jul 5, 5:12 pm, David J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://destiney.com/blog/rubyonrails-model-controller-lists)

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 7, 2007, 9:48am UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/5 "2007-07-07T09:48:20Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![elegant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@elegant](https://www.ruby-forum.com/u/elegant)\
**Post date:** [July 6, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/problem-with-discovering-available-controllers-through-refle/108691/6 "2007-07-06T14:58:31Z")

</div>

Hi –

On Thu, 5 Jul 2007, removed\_email\_address@domain.invalid 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

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))
