attr_json
attr_json copied to clipboard
improvements to "nested attributes"
This confusing to talk/think about. But some things have been a bit inconvenient with form handling, that we can possibly take care of with our _attributes=
methods, which are of course pretty much just there for form handling (I think?), via Rails analogy for associations using _attributes=
methods.
- if i have a nested object on a form, and ALL it's inputs are left empty, I really want to remove it from the DB, not leave it in the DB with all empty-string attributes
- for a single (not array) embedded model... if I leave all the inputs empty, I want to DELETE it, not just leave it there empty
- For a single (not array) embedded model, an easier way to make a form taht automatically "builds" it when needed?
Not sure if these would be universal wants. Or if they'd need to be configurable somehow.
- even without nested models, do I want empty strings in the DB instead of nil when form is submitted with nothing in the box? (But this is an issue with ordinary Rails too? How does Rails handle it?)
- This could maybe be done with custom types or type options. https://discuss.rubyonrails.org/t/database-fields-are-polluted-with-both-nil-and-empty-values-when-submitting-forms/74877/6
- For general rails, there's a third-party gem. might be usable here too... https://github.com/holli/auto_strip_attributes
In general, to "solve" this I'd want to spend some more time testing what Rails does in "ordinary" circumstances, including to_many and has_one inline editing... if possible, it would be nice to match rails, but if what Rails does is too un-helpful, we coudl maybe do better/different.