views:

329

answers:

1

hi all

I have a product model that has many sections and a section can belong to many products.

The section model has subclasses as features, standardAccessories and OptionalAccessories in a STI. Each having field title, body, image url and (optionalAccessories) has price.

my models are

class Product < ActiveRecord::Base  
 has_and_belongs_to_many :categories  
 has_and_belongs_to_many :sections    
end



class Section < ActiveRecord::Base  
 has_and_belongs_to_many :products
end



class Feature < Section
end 

class Standard < Section
end 

class Option < Section
end

In my products controller i can do this

@product.sections.build

but i want to be able to get to the subclasses like something like this

@product.features.build

@product.standards.build

@product.options.build

BUT it just errors with "undefined method 'features' " etc

Please can anyone tell me how to do this ??

Thanks alot in advance rick

+1  A: 

Product doesn't have those methods cause they were never defined. You need to define relationships in your products class to get the features/standards/options methods

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

will give you better understanding of what defining relationships is giving you

ErsatzRyan