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 ArchiveOverlay

#assign

Methods included from UploaderResponses

#failed_uploader_response, #successful_uploader_response

Methods inherited from ResourcesController

#edit, #new, #resource_filters, #resource_filters_for_select, #resource_handler, #resource_has_deprecated_filters, #resource_has_filters

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #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



42
43
44
45
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 42

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

#destroyObject



60
61
62
63
64
65
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 60

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



67
68
69
70
71
72
73
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 67

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

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 15

def index
  @query = Attachment.ransack(search_filter_params[:q])
  @query.sorts = "name asc" if @query.sorts.empty?
  @attachments = @query.result

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

  if search_filter_params[:filter].present?
    @attachments = apply_filters(@attachments)
  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.



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

def show
  render :show
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 47

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