Reputation: 4867
Suppose I have 3 models A B C
, with
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
and in my view I have some nested forms
= form_for @A do |f|
...
= f.fields_for :Cs do |builder|
...
but I get an error
ArgumentError (No association found for name `C'. Has it been defined yet?)
What did I do bad ?
Upvotes: 1
Views: 62
Reputation: 11629
I think you should add :
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
Upvotes: 1