嵌套表单和nested_attributes问题

时间:2013-08-21 17:17:54

标签: ruby-on-rails ruby forms

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

我做了什么坏事?

2 个答案:

答案 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

相关问题