Subscribe to my Feed, follow me on Twitter, recommend me on Working With Rails or see my code on GitHub
ActsAsFile
ActsAsFile is a Rails plugin which saves (uploaded) files to the file system.
Installing
Download the plugin from Github and put it in your vendor/plugins directory.
Using
class Upload < ActiveRecord::Base
acts_as_file
self.save_path = File.join(RAILS_ROOT, 'public', 'uploads')
self.read_path = 'uploads'
end
class UploadsController < ActionController::Base
def create
upload = Upload.new(params[:upload])
if upload.save
flash[:notice] = 'File saved'
redirect_to upload_url(upload)
else
flash[:error] = 'Could not save file'
redirect_to new_upload_url
end
end
end
