Hey guys, I am trying to run a proccess by submitting an AJAX form:
<% form_remote_tag :url => {:controller => 'sender', :action => 'send'} do %>
<input id="messsageinput" type="text" size="44" name="command"/>
<%= submit_tag('Send', :id => 'button') %>
<% end %>
Then, the ‘send’ action creates a new BackgrounDRB job and does some render :update magic:
MiddleMan.worker(:transmit_worker).async_transmit(:arg => {:linkes => linkes, :command => params[:command], :userid => current_user.id}, :job_key => current_user.id)
render :update do |page|
page.insert_html :bottom, 'ajaxholder', :partial => 'transmit'
page[:cominput].clear
end
the part where I’m stuck is I am trying to somehow have the page check a ‘getstatus’ action that checks the progress of the job and renders appropriately and then stop checking when the job is reported done. Any suggestions please?
Alright, I found a solution. I had to use a bit of javascript to check if a variable is set true every 2 seconds and if it is run the AJAX updater (sort of like a periodical but with a variable on/off switch:
Then use a body onload=”inits()” to initiate the script. The controller you pass the command to execute the worker should assign checkstatus a value of 1:
Finally, in the status checking method, set it to reset the variable when completed to turn of the periodical check: