I did some hacking on this in a Rails app and got basic ajax calls
returning the status in JSON.  The main change to Mongrel was the
addition of Rails' MIME parsing classes.  The progress status then
looks like:

respond_to do |accepts|
 accepts.html { out.write("size: #{status['size']}\nreceived:
#{status['received']}\n") }
 accepts.js do
   head['Content-Type'] = 'text/javascript'
   out.write("{size:#{status['size']},received:#{status['received']}}")
 end
end if status

Here's the simple rails view / javascript I used to conduct the test:

<% @upid = Time.now.to_i %>
<%= start_form_tag "[EMAIL PROTECTED]", :multipart => true,
:onsubmit => "monitorUploadProgress([EMAIL PROTECTED])" %>
 <p><%= file_field_tag :upload %></p>
 <p><%= submit_tag :Upload %></p>
</form>

<div id="results"></div>

function monitorUploadProgress(upid) {
 new PeriodicalExecuter(function() {
   new Ajax.Request('/progress?upload_id=' + upid, {
     asynchronous:true, evalScripts:true, method:'get',
     onComplete:function(request) {
       new Insertion.Bottom('results', "<pre><code>" +
request.responseText + "</code></pre>");
     }
   });
 }, 3);
}

--
Rick Olson
http://techno-weenie.net

Attachment: mongrel_responds_to.diff
Description: Binary data

_______________________________________________
Mongrel-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-users

Reply via email to