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
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/effective/s3_uploads_controller.rb', line 10 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) if @asset.save render(:text => {:id => @asset.id, :s3_key => asset_s3_key(@asset)}.to_json, :status => 200) else render(:text => '', :status => 400) end end |
#update ⇒ Object
24 25 26 27 28 29 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 |
# File 'app/controllers/effective/s3_uploads_controller.rb', line 24 def update @asset = Effective::Asset.find(params[:id]) EffectiveAssets.(self, :update, @asset) unless params[:skip_update] # This is useful for the acts_as_asset_box Attach action if update_placeholder_asset(@asset, params) == false render :text => '', :status => :unprocessable_entity return end 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] = 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 => }, :status => 200, :content_type => 'text/html' else render :text => '', :status => 200 end end |