Dynamic Nested Forms with Turbo Discussion
Thanks for this lesson, it's very helpful.
One small tip in case anybody else runs into an error about UnknownAttributeError
when using this approach for accepts_nested_attributes
on an association that uses has_one
instead of has_many
. In the has_one
setup, the parameters hash does not need the "id" used in the fields_for()
call. If you include it then you get the UnknownAttributeError
because of the id. This is nothing to do with turbo and can be reproduced in the rails console.
So, if using has_many, then include the "id"s in the fields_for.
If using has_one, do not!
Hey Sean! Glad to hear that you found this lesson helpful. Also, thanks a bunch for sharing your tip about doing this with has_one
relationships! I'm sure that will come in handy for folks.