Using Has_one Associations With The Cocoon Gem In Rails

Posted By Weston Ganger

Turns out that using the cocoon gem with a has_one association can be a little weird.

My first point is that you may be better off trying not to use cocoon for has_one associations but if its deeply nested you may have no choice.

We have to add 'force_non_association_create' to the 'link_to_add_association' to make it work. If you do not add this it will create a new association each time you load the form.

= link_to_add_association('add something', @form_obj, :comments, force_non_association_create: true)

Related External Links:

Article Topic:Software Development - Ruby / Rails

Date:May 07, 2015