User new direct uploads controllers action on imageable.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user