Forum: Ruby on Rails uninitialized constant (NameError)

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.
Thomas K. (Guest)
on 2006-02-19 06:54
Anyone knows why Test #1 works, but not Test #2

Test #1
=======

  require 'contact/company'
  require 'contact/company_office'

  def main
    @companies = Contact::Company.find(:all,
                 :include=>['company_office'],
                 :limit=>20)
  end
  main

Test #2
=======

  require 'contact/company'
  require 'contact/company_office'

  def main
    puts Contact::Company.name  # the only difference from test 1
    @companies = Contact::Company.find(:all,
                    :include=>['company_office'],
                    :limit=>20)
  end
  main

In (2), I am getting the following

/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:892:in
`guard_against_missing_reflections': Association was not found; perhaps
you misspelled it?  You specified :include => :company_office
(ActiveRecord::ConfigurationError)
 from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:890:in
`guard_against_missing_reflections'
 from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations.rb:846:in
`find_with_associations'
 from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:395:in
`find'
 from ./search.rb:12:in `main'
 from ./search.rb:21
 from /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
 from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require'
 from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:39:in
`require_or_load'
  ... 22 levels...
 from ../../../config/../app/models/contact/company.rb:5
 from /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
 from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require'
This topic is locked and can not be replied to.