about summary refs log tree commit homepage
path: root/examples/rails_app-2.3.4/app
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-12 19:32:46 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-12 19:32:46 -0800
commitb5419dc0e819550b5db0bc18579d8243477c53f2 (patch)
tree6abaca5ea13b00bf936572812996c9c0480a1158 /examples/rails_app-2.3.4/app
parent701405d00364c63c0efbf11a39368dd2cbee0053 (diff)
downloadupr-b5419dc0e819550b5db0bc18579d8243477c53f2.tar.gz
JSON compatible with Ry Dahl's Ajax.Pull + example
Ry posted about it here:
  http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html

This is technically superior compared to all the existing interfaces
since it only requires only one, long-running client-side HTTP request.
I would imagine it's possible for a JavaScript programmer to be capable
of even removing the need for an extra request entirely, I'm not that
programmer...
Diffstat (limited to 'examples/rails_app-2.3.4/app')
-rw-r--r--examples/rails_app-2.3.4/app/controllers/files_controller.rb24
-rw-r--r--examples/rails_app-2.3.4/app/views/files/pull.html.erb46
2 files changed, 63 insertions, 7 deletions
diff --git a/examples/rails_app-2.3.4/app/controllers/files_controller.rb b/examples/rails_app-2.3.4/app/controllers/files_controller.rb
index 004c13e..a0fdbb1 100644
--- a/examples/rails_app-2.3.4/app/controllers/files_controller.rb
+++ b/examples/rails_app-2.3.4/app/controllers/files_controller.rb
@@ -1,14 +1,15 @@
 require 'digest/sha1'
 
 class FilesController < ApplicationController
-  # used by streaming upload progress
+  # used by jQuery streaming upload progress
   def new
-    if request.post?
-      size, hexdigest = _read_sha1_size
-      msg = "Successfully upload file (size: #{size}, sha1: #{hexdigest})"
-      flash[:notice] = msg
-      redirect_to "/files/new"
-    end
+    _sha1_flash_self
+  end
+
+  # based on Ry Dahl's streaming AJAX pull:
+  # http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html
+  def pull
+    _sha1_flash_self
   end
 
   def index
@@ -51,4 +52,13 @@ private
     [ file.size, digest.hexdigest ]
   end
 
+  def _sha1_flash_self
+    if request.post?
+      size, hexdigest = _read_sha1_size
+      msg = "Successfully upload file (size: #{size}, sha1: #{hexdigest})"
+      flash[:notice] = msg
+      redirect_to :action => params[:action]
+    end
+  end
+
 end
diff --git a/examples/rails_app-2.3.4/app/views/files/pull.html.erb b/examples/rails_app-2.3.4/app/views/files/pull.html.erb
new file mode 100644
index 0000000..275704d
--- /dev/null
+++ b/examples/rails_app-2.3.4/app/views/files/pull.html.erb
@@ -0,0 +1,46 @@
+<html>
+  <head>
+<!-- http://rubyforge.org/pipermail/mongrel-users/2007-July/003747.html -->
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+    <title>streaming upload progress test</title>
+    <%= javascript_include_tag 'ajax_pull/prototype-1_5_1.js' %>
+    <%= javascript_include_tag 'ajax_pull/ajax_pull.js' %>
+    <%= javascript_include_tag 'ajax_pull/upload_progress.js' %>
+  </head>
+  <body>
+<%
+upid = "#{Time.now.to_i}.#{rand}"
+act = { :action => 'pull', :upload_id => upid }
+opt = {
+  :multipart => true,
+  :target => 'upload-target',
+  :onsubmit => "UploadProgress.begin('#{upid}')"
+}
+-%>
+
+    <% if flash[:notice] %>
+      <div class="notice"><%= flash[:notice] %></div>
+    <% end %>
+    <p><%= link_to "#{upid} (single)",
+          :action => 'status', :upload_id => upid %></p>
+    <p><%= link_to "#{upid} (stream)",
+           "/progress?long&upload_id=#{upid}" %></p>
+
+    <% form_tag(act, opt) do %>
+      <div><p><%= file_field_tag :data %></p></div>
+      <p><%= submit_tag :Upload %></p>
+    <% end %>
+
+    <p>Below is the results <code>div</code></p>
+    <div id="results">(nothing)</div>
+
+    <p>Below is the progress bar <code>div</code></p>
+    <div id="progress-bar"></div>
+
+    <p>Below is the debug list</p>
+    <ol id="debug"></ol>
+
+    <iframe id="upload-target" name="upload-target" src="about:blank"></iframe>
+
+  </body>
+</html>