This may be a stupid question but I seriously can not find what’s
wrong.
Using Rails 2.3 and Ruby 1.8.7 I have:
class Category < ActiveRecord::Base
has_many :categories_users
has_many :users, :through => :categories_users
%I skip other things here
end
class User < ActiveRecord::Base
has_many :categories_users
has_many :categories, :through => :categories_users
end
class CategoryUser < ActiveRecord::Base
validates_presence_of :category_id, :user_id
belongs_to :category
belongs_to :user
end
and the migration was:
def self.up
drop_table :categories_users
create_table :categories_users do |t|
t.integer :category_id, :user_id
t.timestamps
end
end
I added the timestamps out of desperation, dont think they are
needed.
I really can not see what’s wrong with this set up but:
$ script/console
Loading development environment (Rails 2.3.2)
a =Category.new
/home/jordi/sources/estudio/app/models/category.rb:60: warning: don’t
put space before argument parentheses
=> #<Category id: nil, name: nil, created_at: nil, updated_at: nil,
public: false, created_by: 1>a.users
NameError: uninitialized constant Category::CategoriesUser
from /home/jordi/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/
active_support/dependencies.rb:105:inconst_missing' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:2204:in
compute_type’
from /home/jordi/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/
active_support/core_ext/kernel/reporting.rb:11:insilence_warnings' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:2200:in
compute_type’
from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/
active_record/reflection.rb:156:insend' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/reflection.rb:156:in
klass’
from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/
active_record/reflection.rb:257:insource_reflection' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/reflection.rb:257:in
collect’
from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/
active_record/reflection.rb:257:insource_reflection' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/reflection.rb:288:in
check_validity!’
from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/
active_record/associations/has_many_through_association.rb:5:in
initialize' from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/associations.rb:1277:in
new’
from /home/jordi/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/
active_record/associations.rb:1277:in `users’
from (irb):2
I have being like 2 days trying to solve this, I am sure is some
evident and stupid thing. Any hint will be very welcomed.