
activeupload
Overview
ActiveUpload is Rails plugin that allows you to quickly and easily accept uploaded files and attach them to any model in your application. It uses a slightly modified version SWFUpload to create an elegant user experience, while at the same time being simple and flexible for the developer.
ActiveUpload also works with ActiveScaffold. See the ActiveScaffold section below for details.
Installation
To install and and use the plugin, perform the following steps.
First install the plugin:
./script/plugin install http://activeupload.googlecode.com/svn/trunk/activeupload/
Second, generate the migration, model and controller
./script/generate activeupload
Third, add the following lines to any model you wish to attach files to: ``` has_many :attachments, :as => :attachable
def attachment_id=(attachment_id) unless attachment_id.blank? attachments.clear attachment_ids = attachment_id.split(",") attachment_ids.each do |a_id| unless a_id.blank? attachment = Attachment.find(a_id) attachments << attachment end end end end
def attachment_id result = "" if attachments attachments.each do |attachment| result << ",#{attachment.id}" end end result end ```
Fourth, add the form helpers to your new and edit views:
<p>
<b>Attachments</b><br />
<%= f.attachments_field :attachment_id, { :add => "true", :edit =>"true", :filesize => 30720, :filetypes => [ "*.gif", "*.jpg", "*.png" ] } %>
</p>
Fifth, add the view helper to your show view:
<p>
<b>Attachments</b>
<%= view_attachments_field(@bench, {}) %>
</p>
Sixth and lastly, add the javascript and stylesheets to your layout:
<%= javascript_include_tag :defaults %>
<%= stylesheet_link_tag 'swfupload_theme' %>
<%= javascript_include_tag "swfupload_callbacks.js" %>
<%= javascript_include_tag "SWFUpload.js" %>
ActiveScaffold
ActiveUpload works well with ActiveScaffold. To get ActiveScaffold to render the correct upload forms you must create a partial form override. Luckily, ActiveUpload comes with one. In the plugin's public directory ($PROJECT/vendor/plugins/activeupload/public/) you will find a file named attachment_id_form_column.rhtml. Copy that file to your models views directory ($PROJECT/app/views/$MODEL/).
cp vendor/plugins/activeupload/public/_attachment_id_form_column.rhtml app/views/model
Since attachment_id is a virtual column, you will need to tell ActiveScaffold to use it, you can do that by adding the following code to your model's controller:
active_scaffold :model_name do |config|
config.create.columns = [:column1, :column2, :attachment_id]
config.update.columns = [:column1, :column2, :attachment_id]
end
Finally, add the following code to your attachments_controller:
active_scaffold
Project Information
- License: MIT License
- 9 stars
- svn-based source control
Labels:
assaydepot
fileuploads
SWFUpload
Ruby
Rails
RubyonRails
files
upload
plugin
AssayDepot