Class: Effective::S3UploadsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::S3UploadsController
- Defined in:
- app/controllers/effective/s3_uploads_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
When we create an Asset, we're effectively reserving the ID But the Asset itself isn't really there or uploaded yet.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
When we create an Asset, we're effectively reserving the ID But the Asset itself isn't really there or uploaded yet. But we want to start uploading to the final s3 path
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/effective/s3_uploads_controller.rb', line 15 def create # Here we initialize an empty placeholder Asset, so we can reserve the ID @asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder') @asset.extra = params[:extra] if params[:extra].kind_of?(Hash) EffectiveAssets.(self, :create, @asset) begin @asset.save! render(body: {:id => @asset.id, :s3_key => asset_s3_key(@asset)}.to_json, :status => 200) rescue => e render(:body => e., :status => 500) end end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/effective/s3_uploads_controller.rb', line 30 def update @asset = Effective::Asset.find(params[:id]) EffectiveAssets.(self, :create, @asset) unless params[:skip_update] # This is useful for the acts_as_asset_box Attach action if update_placeholder_asset(@asset, params) == false render :body => '', :status => :unprocessable_entity return end end # Kind of a hacky way of saving IFRAME uploads without joining them to anything if params[:attachable_object_name] == EffectiveAssets::IFRAME_UPLOADS Effective::Attachment.new(asset: @asset, box: EffectiveAssets::IFRAME_UPLOADS, position: 0).save! end # If the attachment information is present, then our input needs some attachment HTML if params.key?(:attachable_object_name) = Effective::Attachment.new .attachable_type = params[:attachable_type].try(:classify) .attachable_id = params[:attachable_id].try(:to_i) .asset_id = @asset.try(:id) .box = params[:box] .position = 0 attachable_object_name = params[:attachable_object_name].to_s = params[:attachment_actions] = !['0', 'f', 'false', 'off'].include?(params[:attachment_links].to_s.downcase) = case params[:attachment_style].to_s when 'table' 'attachment_as_table' when 'list' 'attachment_as_list' else # :thumbnail, nil, or anything 'attachment_as_thumbnail' end render :partial => "asset_box_input/#{}", :locals => {:attachment => , :attachable_object_name => attachable_object_name, :attachment_actions => , attachment_links: }, :status => 200, :content_type => 'text/html' else render :body => '', :status => 200 end end |