Ask A Question

Notifications

You’re not receiving notifications from this thread.

Remote form - update partial in Rails 6

Tim Dowling asked in Rails

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?

Reply

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:

  1. 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.

  2. 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.

Reply

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!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,972+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.