Performance: Nested attributes
MEDIUM IMPACT
Nested attributes affect server response time and client rendering when handling complex forms with multiple associated records.
class Project < ApplicationRecord has_many :tasks accepts_nested_attributes_for :tasks end # In the form view: <%= form_with model: @project do |f| %> <%= f.fields_for :tasks do |task_fields| %> <%= task_fields.text_field :name %> <% end %> <%= link_to 'Add Task', '#', id: 'add-task' %> <% end %> # Use JavaScript to add tasks dynamically instead of loading all at once
class Project < ApplicationRecord has_many :tasks accepts_nested_attributes_for :tasks end # In the form view: <%= form_with model: @project do |f| %> <%= f.fields_for :tasks do |task_fields| %> <%= task_fields.text_field :name %> <% end %> <% end %> # Loads all tasks without pagination or limits
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Render all nested records at once | High number of nodes | Multiple reflows proportional to records | High paint cost due to large DOM | [X] Bad |
| Limit nested records and add dynamically | Reduced nodes initially | Single reflow on load | Lower paint cost | [OK] Good |