Dave
Joined
Activity
Managed to get something working by putting the fields_for record_name attribute "project[tasks_attributes][#{task.persisted? ? task.id : task.object_id }]" in a variable and then pass that variable as an parameter to notes_field in the controller. The data is then passed back to the turbo_stream partial notes_field using a global variable, next in the notes partial you can then concatenate the [notes_attributes][#{note.persisted? ? note.id : note.object_id }] to the variable and use that in the new field_for.
Hope that makes any sense
Nice lessen, Currently I'm trying to create a double nested form like this Project -> task -> note using this technique.
But the issue that I run in to now is that when adding a note when creating a new project and task there is no task.id or task object id in the form field for the notes partial to create the correct name <%= fields_for project[task_attributes][task id][note_attributes][note id]
when using 0 for task id it creates a new task for every note you try to add
What would be a clean solution to get the task id or object id in the notes partial?
I ran into the same problem as you, what fixed it for me was setting a custom local variable name using the as: option.
<%= render partial: "product", collection: @products, as: :item %>