← Back to Upcase

Nested lists of options

(Bastian Platz) #1

The situation is the following: you have a model and this model has_many :options which are actually only a text field.

How do you do a edit/new form for this model where you can edit any number of options? That includes handling of deletion of exisiting options and generation of new options. How to do the JS for the dynamic extension of the form with additional textfields for the new options?

What to do when the nested model is more complex?

(Ben Orenstein) #2

This is a little annoying to do. Fortunately there’s a good RailsCast on it: http://railscasts.com/episodes/196-nested-model-form-part-1

(Derek Prior) #3

I second the rails cast suggested by Ben, but if you’re a RailsCasts Pro subscriber, there’s also a revised edition of that screencast that is more recent.

I’ve also used the cocoon gem in a previous project to take care of the dynamic addition/deletion javascript code.