User new direct uploads controllers action on imageable.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-19 12:00:59 +02:00
parent 824dd26d5a
commit 966ff4dc03
19 changed files with 225 additions and 135 deletions

View File

@@ -3,10 +3,8 @@ class ImagesController < ApplicationController
before_filter :find_imageable, except: :destroy
before_filter :prepare_new_image, only: [:new, :new_nested]
before_filter :prepare_image_for_creation, only: :create
before_filter :find_image, only: :destroy
load_and_authorize_resource except: :upload
skip_authorization_check only: :upload
load_and_authorize_resource
def new
end
@@ -46,32 +44,6 @@ class ImagesController < ApplicationController
end
end
def destroy_upload
@image = Image.new(cached_attachment: params[:path])
@image.set_attachment_from_cached_attachment
@image.cached_attachment = nil
@image.imageable = @imageable
if @image.attachment.destroy
flash.now[:notice] = t "images.actions.destroy.notice"
else
flash.now[:alert] = t "images.actions.destroy.alert"
end
render :destroy
end
def upload
@image = Image.new(image_params.merge(user: current_user))
@image.imageable = @imageable
if @image.valid?
@image.attachment.save
@image.set_cached_attachment_from_attachment(URI(request.url))
else
@image.attachment.destroy
end
end
private
def image_params
@@ -83,10 +55,6 @@ class ImagesController < ApplicationController
@imageable = params[:imageable_type].constantize.find_or_initialize_by(id: params[:imageable_id])
end
def find_image
@image = Image.find(params[:id])
end
def prepare_new_image
@image = Image.new(imageable: @imageable)
end