1

假设我有 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?)

我做错了什么?

4

2 回答 2

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
于 2013-08-21T17:22:05.513 回答
1

我认为has_many :Csclass A.

于 2013-08-21T17:22:21.267 回答