Association problem

Hi, I'm new to ruby on rails. So i think i have association problems.

Given the three model classes with their associations:

# user.rb
class User < ActiveRecord::Base
  has_many :product_groups
  has_many :products, :through=>:product_groups

# product_group.rb
class ProductGroup < ActiveRecord::Base
  has_many :products
  belongs_to :user

# product.rb
class Product < ActiveRecord::Base
  belongs_to :product_group
  has_one :user

So when i trying add new product. I get errors.
# products_controller.rb
  def new
    @product =
The error I'm receiving is:

   NoMethodError (undefined method `products' for #<Class:0x2ca50b0>):
     app/controllers/products_controller.rb:27:in `new'
     -e:2:in `load'

I'm confused, can anybody help me?

A collection of product_groups doesn't have a products method
(individual product group do).
Users have a products association, so why not do ? (Although I'm not sure if you can do a
has_many through where the join model has a has_many)


This is a example. I solve it. Thank you.