# subclasses\_of different result in second call

**URL:** <https://discuss.rubyonrails.org/t/subclasses-of-different-result-in-second-call/46229>\
**Category:** rubyonrails-talk\
**Created:** [September 21, 2009, 10:26am UTC](https://discuss.rubyonrails.org/t/subclasses-of-different-result-in-second-call/46229 "2009-09-21T10:26:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrBanabas](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@MrBanabas](https://discuss.rubyonrails.org/u/MrBanabas)\
**Post date:** [September 21, 2009, 10:26am UTC](https://discuss.rubyonrails.org/t/subclasses-of-different-result-in-second-call/46229/1 "2009-09-21T10:26:12Z")

</div>

Hi,

I m using the following code to get all submodels of an sti model:

Dir.glob(RAILS\_ROOT + '/app/models/\*.rb').each { |file| require file} sub\_models = Object.subclasses\_of(sti\_model)

That works perfect in my dev environment (Rails 2.3.3) during the first request, after I ve started my webrick. However, when the second request is handled subclasses\_of returns an array with 0 elements.

Does anybody have a hint for me what I might do wrong?

thanks a lot in advance.. volker

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [September 21, 2009, 12:11pm UTC](https://discuss.rubyonrails.org/t/subclasses-of-different-result-in-second-call/46229/2 "2009-09-21T12:11:04Z")

</div>

> Hi,
> 
> I m using the following code to get all submodels of an sti model:
> 
> Dir.glob(RAILS\_ROOT + '/app/models/\*.rb').each { |file| require file} sub\_models = Object.subclasses\_of(sti\_model)
> 
> That works perfect in my dev environment (Rails 2.3.3) during the first request, after I ve started my webrick. However, when the second request is handled subclasses\_of returns an array with 0 elements.
> 
> Does anybody have a hint for me what I might do wrong?

Because using require (rather than require\_dependency) confuses rails'  
code reloading system (in particular, require thinks the file is  
already loaded so does not loaded it again, since it doesn't know that  
rails has unloaded the previously loaded classes). Also be careful of  
which path (absolute versus just the filename) you use to require the  
file.

Fred
