原创作者: hideto   阅读:1048次   评论:0条   更新时间:2011-05-26    
今天来看看使用upload_progress插件监听文件上传status以及创建AJAX上传progress bar
Requirements:http://sean.treadway.info/articles/2005/07/18/upload-progress-checklist

安装好该插件以及Requirements后,我们就可以在controller里使用了:
class DocumentController < ApplicationController
  upload_status_for :create

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

class Ducoment2Controller < 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

我们在view中这样使用:
<%= form_tag_with_upload_progress({:action => 'create'}, {
      :begin => 'alert("Upload beginning")',
      :finish => 'alert("Upload finished")'}) %>
<%= file_field 'document', 'file' %>
<%= submit_tag "Upload" %>
<%= upload_status_tag %>
<%= end_form_tag %>


BTW:Rails官方插件就介绍到这儿了,补充贴一下Global Changelog:
引用

* Moved acts_as_taggable, browser_filters, and simply_helpful into legacy -- all have either been deprecated or rolled into Rails core already [DHH]

* Resource feeder turned out to be too restrictive and too hard to customize; replace it by atom_feed_helper [DHH]

* Extract dynamic scaffolding plugin from core.  #7700 [Josh Peek]

* Start a global changelog for the official Rails plugins.  [Jeremy Kemper]
评论 共 0 条 请登录后发表评论

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics