1

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 ?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

I think there is a has_many :Cs missing on class A.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.