All the rails casts and drifting ruby vids I have watched make using hotwire look super easy. But they all share the same use case of make records that are unordered or else have a default order.
My use case requires records with an explicit order stored in an order attribute. The records are rendered in that order, and creating new records isn’t trivial since you can create a record at any position and everything else gets shifted, etc.
I have a link which loads the form at any position with the proper order value already set. I have managed to get turbo frames to work for that as well as dismissing the form once it is submitted, but I can’t figure out how to load the new record into the list because I can’t seem to break out of the turbo_frame the form is in to insert the new record.
The markup is like this:
<turbo-frame id="record_1"> ... </turbo-frame> <turbo-frame id="new_record_after_1"> <form ...> </turbo-frame> <turbo-frame id="record_2"> ... </turbo-frame> <turbo-frame id="new_record_after_2"> <form ...> </turbo-frame> <turbo-frame id="record_2"> ... </turbo-frame> ...
As you can see, since the forms are in a different turbo frames and the submission responses will only operate within them, I can’t insert the new record. Even if turbo frames would get replaced outside the initial context, I don’t have a turbo frame that would match.
I have tried using turbo streams as well, which I couldn’t get to work either since the entire list needs to be replaced to adjust ordering and I couldn’t figure out how to get the broadcasts to work, and honestly that approach is a little overkill for what I am doing.
I had all of this working fine with just stimulus, so if I need to I can go back to that, but I figured it was worth a shot to remove some of the complexity I had in my js. Any advice/helps would be awesome. Thank you!