Bryan Bryan - 4 months ago 4x
Ajax Question

How can I update the content from a rails app in all devices being used?

I really don't have a clue on how to do this. So when admin, deletes or adds a posts, I want people who are viewing the app to automatically see the new content without them having to refresh. I researched and some say websockets. But is there any other way to do this? or What is the best way?


Indeed, what you are looking for is websocket. The app will "subscribe" users to a channel (which can be attached to a page for example). Then you create events for this channel, in your case:

 - when an admin create a post, create a create_post event
 - when an admin  delete a post, create a delete_post event

Then, you can trigger actions when a new event is created. When a delete_post event is created, hide the post in the page. When a create_post event is created, append it.

You have multiple solutions for this. Rails 5 includes ActionCable, which is a websocket "system" integrated into rails (Here is a tutorial). Or you have external solutions, such as pusher.