0
我具有以下设置导轨的has_many:通过NameError
class Category < ActiveRecord::Base
has_many :category_products
has_many :products, through: :category_products
end
class Product < ActiveRecord::Base
has_many :category_products
has_many :categories, through: :category_products
end
class CategoryProducts < ActiveRecord::Base
belongs_to :category
belongs_to :product
end
在导轨控制台I尝试使用以下命令 p.category_ids =分配category_ids [1,2](其中p = Product.first)予得到
NameError: uninitialized constant Product::CategoryProduct
有什么建议吗?
感谢
原来,护栏没有为加盟模式类似“多”的名字,创造了一个新的模式称为分类和所有作品100% –