Forum: Ruby on Rails STI and model loading question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
66d1d0df01e4bbb82674a353ea68d6ee?d=identicon&s=25 Josh Kieschnick (jjkiesch)
on 2007-07-30 21:08
(Received via mailing list)
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.
A7f6b372a89349258d08a4d7acb186d4?d=identicon&s=25 Serengeti (Guest)
on 2007-07-30 22:49
(Received via mailing list)
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.
This topic is locked and can not be replied to.