There are a number of queries in this area, but I've yet to find a concrete answer.
I have built a rails app using rails 4. I have a model and controller called 'VirtualServer'
The VirtualServer model stores the name, id, and other attributes about a real virtual machine.
When I call the VirtualServer show action, it renders the show.html.erb
Now I want to dynamically update some information on this page using AJAX. Specifically I want to access some runtime data about the virtual machine that is available from a RESTful API. I have a method in my VirtualServer called stats that uses a 3rd party client to make this request, and it returns data in a hash.
After rendering show, I'd like to be able to poll stats every 10 seconds and render a partial.
Is there an inbuilt way in rails 4, to make ajax requests from a view at a regular interval and render a partial that displays the info?
virtual_server_controller.rb
class VirtualServer < ApplicationController
def show
@virtualServer = VirtualServer.find(params[:id])
end
def stats
vm_id = params[:id]
# Thirdparty code make RESTful request with vm_id
# and return hash
#
@vm_details = client.get_vm_stats(vm_id)
end
end
virtual_server/show.html.erb
<p>
<strong>Name:</strong>
<%= @vnf.name %>
</p>
<!-- need to call VirtualServer.stats and render result every 10 sec -->