假设我有3个模型A B C
,带
class A
has_many :Bs, through: :Cs
accepts_nested_attributes_for :Cs
end
class B
has_many :As, through: :Cs
end
class C
belongs_to :A
belongs_to :B
end
在我看来我有一些嵌套表格
= form_for @A do |f|
...
= f.fields_for :Cs do |builder|
...
但是我收到了错误
ArgumentError (No association found for name `C'. Has it been defined yet?)
我做了什么坏事?
答案 0 :(得分:1)
我认为你应该补充:
class A
has_many :Cs
has_many :Bs, through: :Cs
accepts_nested_attributes_for :Cs
end
class B
has_many :Cs
has_many :As, through: :Cs
end
答案 1 :(得分:1)
我认为has_many :Cs
上缺少class A
。