Has_many and belongs_to question... undefined method error

I get this weird error message in the console when I try and navigate my
relationship via Pool.gms.each()…

Here’s some cose.

class Gm < ActiveRecord::Base
belongs_to :pools
has_many :teams
has_many :players, :through => :teams, :source => :nhl_stat
end

class Pool < ActiveRecord::Base
has_many :gms
end

Example…

pool = Pool.find(1)
=> #<Pool:0xb7278424 @attributes={“last_modified”=>nil, “id”=>“1”,
“salary_cap”=>“40000000”, “pool_name”=>“RHP 07-08 Season - Career
League”, “created”=>nil}>

pool.gms.each() { |g| puts “GM: #{g.user_name}\n” }
NoMethodError: undefined method pool' for Gm:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1235:inmethod_missing’
from ./script/…/config/…/config/…/app/models/gm.rb:9
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:203:in
load_without_new_constant_marking' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:203:inload_file’

etc etc…

Thanks in advance.

You’ve named your belongs _to pools and it should be pool in your Gm
class.

Hence rails is looking for pool and it’s not hence hence the undefined
method.

Cam

On Sep 6, 1:48 pm, Jean N. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs