0
我想用后续查询这样张贴子类别:Rails的控制台复杂的查询
Gender.where(gender: 'Masc').categories.where(name: 'clothes').subcategories.create([{ name: 't-shirt' }])
,但显示这个错误!
rake aborted! NoMethodError: undefined method `subcategories' for Category
我搜索了但无法找到如何使用链接查询创建数据。
Gender Model:
class Gender < ActiveRecord::Base
extend FriendlyId
friendly_id :gender, use: [:slugged, :history]
has_many :categories
has_many :subcategories, through: :categories
has_many :products
accepts_nested_attributes_for :categories
accepts_nested_attributes_for :products
accepts_nested_attributes_for :subcategories
attr_accessible :gender, :categories_attributes, :subcategories_attributes,
end
非常感谢您@mu_is_too_short,但我不知道为什么还显示: NoMethodError:性别负载(0.5毫秒)选择“性别” * FROM“性别” WHERE“gender”。“gender”='Masc' 未定义的方法'categories'for# –
Daniel
你的'Gender'模型是什么样的? –
对,我编辑了问题! – Daniel