Class: FileAttachmentsController
- Inherits:
-
FileShare::ApplicationController
- Object
- ActionController::Base
- ApplicationController
- FileShare::ApplicationController
- FileAttachmentsController
- Defined in:
- app/controllers/file_attachments_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #download ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/file_attachments_controller.rb', line 52 def create if params[:file] # plupload param file_params = { :uploaded_file => params[:file] } if params[:attachable_id] && params[:attachable_type] file_params.merge!({ :attachable_id => params[:attachable_id], :attachable_type => params[:attachable_type] }) end @file_attachment = FileAttachment.new file_params elsif params[:file_attachment] && params[:file_attachment][:uploaded_file] # std form params @file_attachment = FileAttachment.new params[:file_attachment] end if @file_attachment && @file_attachment.save flash[:notice] = "File uploaded." else if @file_attachment flash[:warning] = "Unable to save file attachment: #{@file_attachment.errors..join('; ')}" else flash[:warning] = "No files were selected for upload." end end unless params[:file] # request.xhr? # html5 based multiple uploads are not xhr ? redirect_to_index_or_attachable(:std => 1) # {:std => 1} - make sure the std html form displays else flash.discard render :partial => 'file_attachments/file_attachment', :object => @file_attachment end end |
#destroy ⇒ Object
108 109 110 111 112 113 |
# File 'app/controllers/file_attachments_controller.rb', line 108 def destroy @file_attachment = FileAttachment.find(params[:id]) @file_attachment.destroy flash[:notice] = "Deleted File: #{@file_attachment.name}" redirect_to_index_or_attachable end |
#download ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/controllers/file_attachments_controller.rb', line 44 def download = FileAttachment.find(params[:id]) file_itself = File.open(.full_path, 'r') logger.debug("FILE ATTACHMENT INFO: #{.inspect}") logger.debug("FILE INFO: #{file_itself.inspect}") send_data(file_itself.read, :filename => File.basename(file_itself.path), :stream => true, :buffer_size => 1.megabyte) end |
#edit ⇒ Object
86 87 88 |
# File 'app/controllers/file_attachments_controller.rb', line 86 def edit @file_attachment = FileAttachment.find(params[:id]) end |
#index ⇒ Object
39 40 41 42 |
# File 'app/controllers/file_attachments_controller.rb', line 39 def index @orphans = FileAttachment.orphans @files = FileAttachment.attached end |
#new ⇒ Object
34 35 |
# File 'app/controllers/file_attachments_controller.rb', line 34 def new end |
#show ⇒ Object
36 37 38 |
# File 'app/controllers/file_attachments_controller.rb', line 36 def show @file_attachment = FileAttachment.find(params[:id]) end |
#update ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/file_attachments_controller.rb', line 90 def update @file_attachment = FileAttachment.find(params[:id]) respond_to do |format| if @file_attachment.update_attributes(params[:file_attachment]) format.html do flash[:notice] = "Updated File: #{@file_attachment.name}" redirect_to_index_or_attachable end else format.html do flash.now[:warning] = "The description could not be saved, please try again." render :edit end end format.js end end |