OverviewActiveUpload 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.
InstallationTo 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 activeuploadThird, 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
endFourth, add the form helpers to your new and edit views:
Attachments
<%= f.attachments_field :attachment_id, { :add => "true", :edit =>"true", :filesize => 30720, :filetypes => [ "*.gif", "*.jpg", "*.png" ] } %>
Fifth, add the view helper to your show view:
Attachments
<%= view_attachments_field(@bench, {}) %>
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" %>ActiveScaffoldActiveUpload 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/modelSince 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]
endFinally, add the following code to your attachments_controller:
active_scaffold
Ohloh computes statistics on FOSS projects by examining source code and commit history in source code management systems. This project has no code locations, and so Ohloh cannot perform this analysis
Is this project's source code hosted in a publicly available repository? Do you know the URL? If you do, click the button below and tell us so that Ohloh can generate statistics! It's fast and easy - try it and see!
Copyright
©
2013
Black Duck Software, Inc.
and its contributors, Some Rights Reserved. Unless otherwise marked, this work is licensed under a
Creative Commons Attribution 3.0 Unported License
. Ohloh
®
and the Ohloh logo are trademarks of
Black Duck Software, Inc.
in the United States and/or other jurisdictions. All other trademarks are the property of their respective holders.