app/controllers/alchemy/admin/attachments_controller.rb in alchemy_cms-3.2.1 vs app/controllers/alchemy/admin/attachments_controller.rb in alchemy_cms-3.3.0.rc1

- old
+ new

@@ -1,22 +1,30 @@ module Alchemy module Admin class AttachmentsController < ResourcesController + include UploaderResponses + helper 'alchemy/admin/tags' def index - @attachments = Attachment.all + @query = Attachment.ransack(params[:q]) + @attachments = @query.result + if params[:only].present? @attachments = @attachments.where("file_mime_type LIKE '%#{params[:only]}%'") end if params[:except].present? @attachments = @attachments.where("file_mime_type NOT LIKE '%#{params[:except]}%'") end if params[:tagged_with].present? @attachments = @attachments.tagged_with(params[:tagged_with]) end - @attachments = @attachments.find_paginated(params, 15, sort_order) + + @attachments = @attachments + .page(params[:page] || 1) + .per(15) + @options = options_from_params if in_overlay? archive_overlay end end @@ -24,54 +32,46 @@ # The resources controller renders the edit form as default for show actions. def show render :show end - def new - @attachment = Attachment.new - if in_overlay? - set_instance_variables - end - end - def create @attachment = Attachment.new(attachment_attributes) if @attachment.save - if in_overlay? - set_instance_variables - end - message = _t('File uploaded succesfully', name: @attachment.name) - render json: {files: [@attachment.to_jq_upload], growl_message: message}, status: :created + render succesful_uploader_response(file: @attachment) else - message = _t('File upload error', error: @attachment.errors[:file].join) - render json: {files: [@attachment.to_jq_upload], growl_message: message}, status: :unprocessable_entity + render failed_uploader_response(file: @attachment) end end def update @attachment.update_attributes(attachment_attributes) render_errors_or_redirect( @attachment, - admin_attachments_path(page: params[:page], query: params[:query], per_page: params[:per_page]), - _t("File successfully updated") + admin_attachments_path( + per_page: params[:per_page], + page: params[:page], + q: params[:q] + ), + Alchemy.t("File successfully updated") ) end def destroy name = @attachment.name @attachment.destroy @url = admin_attachments_url( per_page: params[:per_page], page: params[:page], - query: params[:query] + q: params[:q] ) - flash[:notice] = _t('File deleted successfully', name: name) + flash[:notice] = Alchemy.t('File deleted successfully', name: name) end def download @attachment = Attachment.find(params[:id]) - send_data @attachment.file.data, { + send_file @attachment.file.path, { filename: @attachment.file_name, type: @attachment.file_mime_type } end @@ -91,16 +91,8 @@ end def attachment_attributes params.require(:attachment).permit(:file, :name, :file_name, :tag_list) end - - def set_instance_variables - @while_assigning = true - @content = Content.find_by(id: params[:content_id]) - @swap = params[:swap] - @options = options_from_params - end - end end end