Skip to main content

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

Rails • Asked by Arjun Rajkumar

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!


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.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.