All threads / How do I update a page (a row on a table) dynamically?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I update a page (a row on a table) dynamically?

Arjun Rajkumar asked in Rails

I have a page which displays all the products in a shop.

Each time a new product is added - two things happen.
1) The user is taken to the products/index page which shows a list of all the products added - including the new product.
2) A Sidekiq BG job starts. It basically goes to amazon and finds the price of the product added.

As the user is taken the products/index page after they add the product - they see that the new product is added (but the price and other info is empty). I want to somehow update this products/index page dynamically with the details of the new product (which is got via the Sidekiq worker).

I am just thinking how to approach this:

  • Should I somehow get the worker to access this page and update the details?
  • Should I do some polling method on the index page and just refresh it every few minutes.
  • Or should I explore Action Cable to do this.

Any help will be appreciated. Just not sure which is the recommended way to do this..

THank you!

Arjun

ActionCable works great for this. Once the background job retrieves the data, you can have it send an updated partial over to the user and replace it on the page. I do this for server and app status updates on Hatchbox. Works great.

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.