Some how I’m getting NameError: uninitialized constant when accessing a
child models that inherits form the parent model. However, if I access
the parent model first, then the child model is resolved.
What am I doing wrong? My steps are below…
Thanks,
Francis.
./script/generate model Blah type:string
class CreateBlahs < ActiveRecord::Migration
def self.up
create_table :blahs do |t|
t.string :type
t.timestamps
end
end
def self.down
drop_table :blahs
end
end
rake db:migrate
== CreateBlahs: migrating
====================================================
– create_table(:blahs)
-> 0.0989s
== CreateBlahs: migrated (0.0991s)
===========================================
blah.rb:
class Blah < ActiveRecord::Base
end
class Whale < Blah
end
class Dolphin < Blah
end
./script/console
Dolphin.new
NameError: uninitialized constant Dolphin
from
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in
load_missing_constant' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in
const_missing’
from
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in
`const_missing’
from (irb):1Blah.new
=> #<Blah id: nil, type: nil, created_at: nil, updated_at: nil>Dolphin.new
=> #<Dolphin id: nil, type: “Dolphin”, created_at: nil, updated_at: nil>