I have a rails 3 app which uses resque to run long running jobs in the background and I want to create a view to the results on another page
At the moment I have this scenario working
Resque runs a job and writes the info to the database (updates the info entry) as it progresses. Once the job is complete it updates one of the database entries i.e. it sets complete = 1 (complete is created with a value of 0)
Db schema is
create_table "refreshes", :force => true do |t|
t.string "name"
t.string "info"
t.integer "complete"
t.datetime "created_at"
t.datetime "updated_at"
end
Another page view in the app will display the database entry by calling it’s controller and displaying the latest data on a page, this view has a piece of logic to insert a standard JavaScript refresh element if the complete value in the database is not equal to 1
view.html.erb
<% if @refreshes.complete == 0 %>
<meta http-equiv='refresh' content='5'>
<%end%>
<div id="data">
<p>
<b>Name:</b>
<%= @refreshes.name %>
</p>
<p>
<b>Info:</b>
<%= @refreshes.info %>
</p>
</div>
Controller method
def view
@refreshes = Refresh..find(params[:id])
respond_to do |format|
format.html # view.html.erb
format.xml { render :xml => @refreshes }
end
end
this all works fine but it does do a full page reload every 5 seconds when complete is set to 0, and what I want to do is just refresh the div that displays the data ( div id = data) without refreshing the whole page.
I think this can be done using jquery and some JavaScript but I can’t find a way to do it so can anyone help? Or even if you can point me in the direction I would appreciate it Cheers Mike