# STI and model loading question

**URL:** <https://www.ruby-forum.com/t/sti-and-model-loading-question/110778>\
**Category:** Rails\
**Created:** [July 30, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/sti-and-model-loading-question/110778 "2007-07-30T21:08:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [July 30, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/sti-and-model-loading-question/110778/1 "2007-07-30T21:08:32Z")

</div>

when trying to figure out STI i’ve hit a problem…

in my address.rb file i have the following:

class Address \< ActiveRecord::Base

validates\_presence\_of :name, :address\_1, :city, :state, :zip

belongs\_to :order  
end

class BillingAddress \< Address  
end

class ShippingAddress \< Address  
end

now when in the console and i try to access BillingAddress, i get  
“uninitialized constant” errors, but if i access Address first,  
BillingAddress loads up fine. i thought all of the models were loaded  
when the app was started, so why is it not recognizing my sub classes?  
my other question is what i need to put in my code to make sure that i  
can access the subclass even if i haven’t accessed the parent one  
first? i’m guess i need to load it somewhere but i don’t know where or  
what syntax to use.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [July 30, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/sti-and-model-loading-question/110778/2 "2007-07-30T22:49:56Z")

</div>

This one has bitten me before too.

There are a couple of ways around it, but the one that I use is this:

Create separate billing\_address.rb and shipping\_address.rb files in  
your models directory instead of including them in your address.rb  
file.
