In this article we are going to discuss how to build more complex forms using Rails' nested attributes feature. I will show you how to manipulate multiple associated records from a single form and properly set up the models and controller to enable this feature. Also, we are going to discuss common pitfalls and power our form up to make it more dynamic using the gem called Cocoon. This solution allows adding and removing nested fields asynchronously while providing lots of customization options and callbacks.
The source code is available at GitHub.
The demo app is available at sitepoint-nested-forms.herokuapp.com.
Building a Simple Form
For this demo I'll be using Rails 5 but most of the described concepts can be applied to Rails 3 and 4
Go ahead and create a new application without the default testing suite:
Continue reading %Better Nested Attributes in Rails with the Cocoon Gem%
by Ilya Bodrov-Krukowski via SitePoint
No comments:
Post a Comment