Remote form - update partial in Rails 6
This may sound super dumb but is there a new and improved way to remotely update partials in Rails 6. I've used the 'update.js.erb' file before to render the partial but for rails 6 is there an updated pattern or best practice we should be following?
Hey Tim!
This actually might change very soon whenever the "New Magic" DHH keeps talking about gets released.
There are a few good options currently that I like using:
Write a Stimulus JS controller that makes that AJAX request and replaces the partial in the DOM. Rails just needs to render the partial and return that without the layout.
For realtime, you can use CableReady to broadcast the partial from the backend to the frontend with ActionCable. The partial would just need an ID so that it can be searched for and replaced.
Thanks Chris! I've been playing around with a Stimulus Controller to do this and it works great! Good to know it's an ok pattern to use. I have been watching DHH's tweets with anticipation of NEW MAGIC, looking forward to seeing what this sorcery is!