Using Has_one Associations With The Cocoon Gem In Rails

Posted by Weston Ganger on May 07, 2015

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:

Posted in Rails and Tagged with rails cocoon has_one 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts