Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

STI sub classes not loaded until parent is

#91

When using STI, a Uninitialised Constant error is thrown when calling subclasses (Doc in following example) before parent class is called (container in following example).

Ex:

class Container < ActiveRecord::Base
end

class Doc < Container
end

Doc
#=> uninitialized constant Doc
Container
#=> Okay
Doc
#=> Okay

Reported by Ian Ownbey · May 2nd, 2008 @ 01:23 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung

    Works fine for me. Where have you put these classes?

    May 2nd, 2008 @ 02:28 AM

  2. Ian Ownbey
    Ian Ownbey

    ooooo all the STI are in the same file as the model. This could be creating the problem.

    May 2nd, 2008 @ 02:51 AM

  3. Frederick Cheung
    Frederick Cheung

    That will definitely be a problem. If they are both in container.rb, how can the dependencies mechanism know that if you hit const_missing for Doc you need to look in container.rb?

    May 2nd, 2008 @ 09:58 AM

  4. DHH
    DHH
    • State changed from new to resolved

    Auto-loading only works when each class is in its own file. If you want to keep all the files in one, you can always force the load with require_dependency 'container' some where.

    May 3rd, 2008 @ 05:03 PM