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