Class: Alchemy::Admin::AttachmentsController

Inherits:
ResourcesController show all
Includes:
ArchiveOverlay, UploaderResponses
Defined in:
app/controllers/alchemy/admin/attachments_controller.rb

Constant Summary

Constants inherited from ResourcesController

ResourcesController::COMMON_SEARCH_FILTER_EXCLUDES

Instance Method Summary collapse

Methods included from UploaderResponses

#failed_uploader_response, #successful_uploader_response

Methods inherited from ResourcesController

#edit, #new, #resource_handler

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_filter_select, #resource_has_filters, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_header, #resources_instance_variable, #resources_path, #sortable_resource_header_column

Methods inherited from BaseController

#leave

Methods included from Modules

included, #module_definition_for, register_module

Methods included from Alchemy::AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#createObject


37
38
39
40
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 37

def create
  @attachment = Attachment.create(attachment_attributes)
  handle_uploader_response(status: :created)
end

#destroyObject


55
56
57
58
59
60
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 55

def destroy
  name = @attachment.name
  @attachment.destroy
  @url = admin_attachments_url(search_filter_params)
  flash[:notice] = Alchemy.t('File deleted successfully', name: name)
end

#downloadObject


62
63
64
65
66
67
68
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 62

def download
  @attachment = Attachment.find(params[:id])
  send_file @attachment.file.path, {
    filename: @attachment.file_name,
    type: @attachment.file_mime_type
  }
end

#indexObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 11

def index
  @query = Attachment.ransack(search_filter_params[:q])
  @attachments = @query.result

  if search_filter_params[:tagged_with].present?
    @attachments = @attachments.tagged_with(search_filter_params[:tagged_with])
  end

  if search_filter_params[:file_type].present?
    @attachments = @attachments.with_file_type(search_filter_params[:file_type])
  end

  @attachments = @attachments
    .page(params[:page] || 1)
    .per(items_per_page)

  if in_overlay?
    archive_overlay
  end
end

#showObject

The resources controller renders the edit form as default for show actions.


33
34
35
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 33

def show
  render :show
end

#updateObject


42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 42

def update
  @attachment.update(attachment_attributes)
  if attachment_attributes['file'].present?
    handle_uploader_response(status: :accepted)
  else
    render_errors_or_redirect(
      @attachment,
      admin_attachments_path(search_filter_params),
      Alchemy.t("File successfully updated")
    )
  end
end