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

Reply

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.

Reply
Join the discussion
Create an account Log in

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

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

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