Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4402 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

STI subclass not found when referenced as association

Reported by: mikkel@helenius.dk Assigned to: David
Priority: normal Milestone: 1.1
Component: ActiveRecord Version:
Severity: normal Keywords:
Cc:

Description

The following used to work in pre 1.1

class League < ActiveRecord::Base

has_one :bowl_game,:class_name=>"FinalGame"

...

FinalGame is a subclass of Game and is defined in game.rb

in 1.1 it breaks with the stacktrace below.

It can be fixed by adding require 'game' in league.rb

./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:106:in `rake_original_const_missing': uninitialized constant FinalGame

./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1177:in `instance_eval' /opt/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1761:in `const_missing' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:133:in `const_missing' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:135:in `send' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:135:in `const_missing' (eval):1:in `instance_eval' #{RAILS_ROOT}/app/views/turnering/show_archive.rhtml:3:in `_run_rhtml_turnering_show_archive' #{RAILS_ROOT}/app/views/turnering/show.rhtml:13:in `_run_rhtml_turnering_show'

Change History

03/24/06 21:28:19 changed by rick

  • status changed from new to closed.
  • resolution set to invalid.

Don't define multiple classes in the same file. Have game.rb and final_game.rb so that the class loader can find FinalGame.

If you really want that, you'll have to put this in your controllers:

class LeaguesController < ApplicationController
  model :game
end