Posted over 4 years ago. Visible to the public.
Nested forms [2d]
- Understand how nested attributes appear in the params.
- See how the Rails form helpers encode the names of nested inputs.
- Understand how the record and all of its nested attributes are saved in a transaction. That means the entire structure is saved or not.
- Rails Guide: Nested forms
- Popular mistakes when using nested forms
- When aggregating nested children, always exclude children marked for destruction
Exercise: Showtimes for MovieDB
- A movie has a list of showtimes. Each showtime consists of the name of the cinema, and the start time (both can be simple text fields).
- Expand the movie form with a simple interface that allows adding, editing and removing of showtimes. It is fine when you can only add 5 showtimes at a time.
- Showtimes should validate the presence of cinema and date.
- Also add a field
total_showtimesthat caches the number of total showtimes. Do not use Rails' counter cache mechanism.
- When you delete a showtime, does
total_showtimesdecrease as expected?