0

I've been trying to get cocoon working with a form that handles a has_one relationship but no has_many relationships, and come across a few gotchas, such as Cocoon and has_one association .

I'm starting to wonder if I'm taking the wrong approach by using cocoon in this scenario. One reason is that the documentation about cocoon talks about has_many relationships, but not has_one ones. Maybe it's because the only benefits for cocoon is when there's a has_many relationship and you want to dynamically create related objects.

Is cocoon supposed to make relationships easier in a way that's useful for has_one relationships?

Community
  • 1
  • 1
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

1 Answers1

1

In my opinion cocoon is not useful for the has_one relationship. You will note that when we create fields_for for some association then we will have the first field generated by default. So now if you have has_many relation and you need to add more of it then you may use cocoon. For has_one relationship normal rails form will do the trick.

Coocon doesn't make relationships easier rather adding multiple assoicated objects at the same time from a form is made easier using that.

Hope this helps.

Deepesh
  • 6,138
  • 1
  • 24
  • 41