1

These are my models:

class Company < ActiveRecord::Base  
  has_many :products  
end

class Product < ActiveRecord::Base  
  belongs_to :company  
  has_many :prices  
end

class Price < ActiveRecord::Base  
  belongs_to :product  
end

I defined them in routes as nested resources

resources :companies  
namespace :company do  
  scope ":company_id" do  
    resources :products do  
      resources :prices  
      resources :production_capabilities  
    end  
  end  
end

I wanted to put controllers and views in catalogs matching that structure

app/controllers/companies_controller.rb  
app/controllers/company/products_controller.rb  
app/controllers/company/product  
app/controllers/company/product/prices_controller.rb

As soon as i create product directory inside company and i try to call

Company.find(1).products

i get

NoMethodError: undefined method 'quoted_table_name' for Company::Product:Module

Does anybody know what am i doing wrong?

Unixmonkey
  • 18,485
  • 7
  • 55
  • 78
kaczor1984
  • 467
  • 2
  • 12
  • 22

1 Answers1

1

The Rails documentation explicitly recommends that we don't nest resources more than 1 level deep:

http://guides.rubyonrails.org/routing.html#nested-resources

You'll get URLs like this:

/company/1/product/4/price/5

That's not pretty. Try to avoid it.

Fábio Batista
  • 25,002
  • 3
  • 56
  • 68