3. Background
Forms are common in web applications
Forms often end up savingdatato multiple tables
Rails gives us #accepts_nested_attributes_for
Much magic and potentialconfusion
19. Early on, SRPis easy to apply. ActiveRecord
classes handle persistence, associations and not
much else. Butbit-by-bit, they grow. Objects
thatare inherently responsible for persistence
become the de facto owner of all business logic
as well. And ayear or two later you have aUser
class with over 500 lines of code, and hundreds
of methods in it’s public interface.
- 7 Patterns to Refactor FatActiveRecord
Models
20. #accepts_nested_attributes_foris
used, in ActiveRecord classes, to reduce the
amountof code in Rails applications needed to
create/update records across multiple tables
with asingle HTTPPOST/PUT. As with many
things Rails, this is convention-driven...
While this sometimes results in less code, itoften
results in brittle code.
- #accepts_nested_attributes_for (Often)
Considered Harmful