Upload files
Ruby JavaScript
Latest commit c3e8dea Jan 24, 2012 @galetahub Rails 3.2 support
Failed to load latest commit information.
app/assets Rails 3.2 support Jan 24, 2012
lib Rails 3.2 support Jan 24, 2012
vendor/assets Rails 3.2 support Jan 24, 2012
.gitignore Fix issues May 19, 2011
MIT-LICENSE Support multipart upload Dec 13, 2011
README.rdoc Rails 3.2 support Jan 24, 2012
Rakefile Support multipart upload Dec 13, 2011
sunrise-file-upload.gemspec Rails 3.2 support Jan 24, 2012

README.rdoc

Sunrise CMS: File uploader

Install

gem "sunrise-file-upload"

Callbacks

Sunrise::FileUpload::Manager.before_create do |env, asset|
  asset.user = env['warden'].user if env['warden']
end

Sunrise::FileUpload::Manager.after_create do |env, asset|
  asset.user = env['warden'].user if env['warden']
end

Usage

class User < ActiveRecord::Base
  has_one :picture, :as => :assetable, :dependent => :destroy

  fileuploads :picture
end

Find asset by foreign key or guid:

@user.fileupload_asset(:picture)

Views

<%= stylesheet_link_tag "fileupload/application" %>
<%= javascript_include_tag "fileupload/application", "jquery.tmpl.min" %>

<%= form.fileupload :picture %>
<%= form.hidden_field :fileupload_guid if form.object.new_record? %>

<script id="fileupload_tmpl" type="text/x-jquery-tmpl">
  <div class="fileupload-container">
    <div class="fileupload-preview"><img alt="Фото" src="/images/userico.jpg"></div>
    <div class="fileupload-button"><input type="image" value="Оберіть фаіл" src="/images/but_set.png"></div>
    <ul class="fileupload-list" style="display:none;"></ul>
  </div>
</script>

Copyright © 2011 Aimbulance, released under the MIT license