Upload Progress plugin

Plugin details

The upload progress plugin will alter your rails CGI handling to track the uploaded status of multipart/form encoded posts. The plugin will also add helper methods to create an AJAX updating progress bar.

Repositoryhttp://dev.rubyonrails.com/svn/plugins/upload_progress Author Sean Treadway, Thomas Fuchs Tags AJAX, Uploads LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://dev.rubyonrails.com/svn/plugins/upload_progress

== Automatic updating on upload actions ==

class DocumentController < ApplicationController   
  upload_status_for  :create

  def create
    # ... Your document creation action
  end
end


The +upload_status_for+ macro will override the rendering of the action passed if +upload_id+ is found in the query string. This allows for default behavior if Javascript is disabled. If you are tracking the upload progress then +create+ will now return the cleanup scripts that will terminate the polling of the upload status.

== Customized status rendering ==

class DocumentController < ApplicationController   
  upload_status_for  :create, :status => :custom_status

  def create
    # ... Your document creation action
  end

  def custom_status
    # ... Override this action to return content to be replaced in
    # the status container
    render :inline => "<%= upload_progress.completed_percent rescue 0 %> % complete", :layout => false
  end
end



The default status action is +upload_status+. The results of this action are added used to replace the contents of the HTML elements defined in +upload_status_tag+. Within +upload_status+, you can load the Progress object from the session with the +upload_progress+ method and display your own results.

Completion of the upload status updating occurs automatically with an +after_filter+ call to +finish_upload_status+. Because the upload must be posted into a hidden IFRAME to enable Ajax updates during the upload, +finish_upload_status+ overwrites the results of any previous +render+ or +redirect_to+ so it can render the necessary Javascript that will properly terminate the status updating loop, trigger the completion callback or redirect to the appropriate URL.

== Basic Example (View) ==

<%= form_tag_with_upload_progress({:action => 'create'}, {:finish => 'alert("Document Uploaded")'}) %>
<%= upload_status_tag %>
<%= file_field 'document', 'file' %>
<%= end_form_tag %>



== Basic Example (Controller) ==

class DocumentController < ApplicationController
  upload_status_for :create

  def create
    @document = Document.create(params[:document])
  end
end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: maxim_kulkin, 8 months ago