app/controllers/brightcontent/attachments_controller.rb in brightcontent-attachments-2.0.33 vs app/controllers/brightcontent/attachments_controller.rb in brightcontent-attachments-2.1.0
- old
+ new
@@ -1,12 +1,11 @@
require_dependency "brightcontent/application_controller"
module Brightcontent
class AttachmentsController < ApplicationController
-
def show
- @attachments = Attachment.where(attachable_type: params[:type].classify, attachable_id: params[:id])
+ @attachments = Attachment.for_attachable(params[:type], params[:id])
render layout: false
end
def create
@attachment = Attachment.new(attachment_params)
@@ -16,17 +15,21 @@
render json: @attachment.errors, status: :unprocessable_entity
end
end
def destroy
- attachment = Attachment.destroy(params[:id])
- redirect_to attachment.attachable
+ Attachment.destroy params[:id]
+ head :no_content
end
+ def reposition
+ Attachment.for_attachable(params[:type], params[:id]).reposition! params[:positions]
+ head :no_content
+ end
+
private
def attachment_params
- params.permit(:attachable_id, :attachable_type, :asset)
+ params.require(:attachment).permit(:attachable_id, :attachable_type, :asset)
end
-
end
end