# Is old school STI broken? How would you do the same now?

**URL:** <https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458>\
**Category:** Rails\
**Created:** [April 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458 "2006-04-03T18:57:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 3, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458/1 "2006-04-03T18:57:19Z")

</div>

So this new STI :through thing is still not clear to me. I have a  
project now where I’m using this:

class List \< ActiveRecord::Base  
belongs\_to :user  
end

class StaticList \< List  
has\_and\_belongs\_to\_many :items  
end

In the script/console:

> > StaticList.create  
> > NameError: uninitialized constant StaticList

What? ok, fine. So a List.create would be in order, except no matter  
what is passed into :type =\>, it ends up with “List” in the database’s  
type column. Is there a better way to model this with the :through  
feature? Why isn’t rails finding the StaticList class? Is this a bug? A  
feature? The definition is in the same file as class List…

Thanks for any pointers,

–  
Matthew B. :: removed\_email\_address@domain.invalid  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 3, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458/2 "2006-04-03T19:31:03Z")

</div>

Have you declared the list model in application.rb?

class ApplicationController \< ActionController::Base  
model :list

You need to do this so the application knows about StaticList class (It  
will only know about the subclass once it’s read the list.rb model  
declaration)

Hope this helps.  
Chris T

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 3, 2006, 8:12pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458/3 "2006-04-03T20:12:18Z")

</div>

Chris T wrote:

> Have you declared the list model in application.rb?
> 
> class ApplicationController \< ActionController::Base  
> model :list

right, models/list.rb is definitly getting loaded, I run tests on it, I  
have been using it to create, that’s not a problem. As far as I recall  
(though i have not dug through the current rails code to be sure) every  
class in list.rb will be loaded. I could throw foobarfoo.rb in the  
models directory and it’s contents would be loaded.

> You need to do this so the application knows about StaticList class (It  
> will only know about the subclass once it’s read the list.rb model  
> declaration)

Well, once it reads the list.rb file yeah, which it is doing. Hence my  
own confusion 🙂

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 3, 2006, 8:12pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458/4 "2006-04-03T20:12:30Z")

</div>

Chris T wrote:

> Have you declared the list model in application.rb?
> 
> class ApplicationController \< ActionController::Base  
> model :list

right, models/list.rb is definitly getting loaded, I run tests on it, I  
have been using it to create, that’s not a problem. As far as I recall  
(though i have not dug through the current rails code to be sure) every  
class in list.rb will be loaded. I could throw foobarfoo.rb in the  
models directory and it’s contents would be loaded.

> You need to do this so the application knows about StaticList class (It  
> will only know about the subclass once it’s read the list.rb model  
> declaration)

Well, once it reads the list.rb file yeah, which it is doing. Hence my  
own confusion 🙂

–  
Matthew B. :: removed\_email\_address@domain.invalid  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 4, 2006, 4:18pm UTC](https://www.ruby-forum.com/t/is-old-school-sti-broken-how-would-you-do-the-same-now/93458/5 "2006-04-04T16:18:46Z")

</div>

for the magic to happen, you need TWO files. One called list.rb  
defines List and one called static\_list.rb that defines StaticList.

The spells don’t work if you don’t pronounce them properly. 😉

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739
