Setup: In my environment, a Java program writes to a PostgreSQL database table called readings
continuously, say every second.
I am building a rails app that connects to the same database and displays those readings. Here is a picture of the readings being displayed statically.
Problem: To see new readings, I have to refresh.
Question: How can I use ActionController::Live to make this page show new records? I imagine that I need to poll the database for new records and update the @readings
variable but I do not know how.
Here is the beginning of readings_controller.rb
.
class ReadingsController < ApplicationController
include ActionController::Live
before_action :set_reading, only: [:show, :edit, :update, :destroy]
# GET /readings
# GET /readings.json
def index
@search = Reading.search(params[:q])
@readings = @search.result.order('time DESC').paginate(:page => params[:page])
end