Class: Alchemy::Admin::AttachmentsController

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

Constant Summary

Constants included from ResourceFilter

ResourceFilter::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_handler

Methods included from ResourceName

#controller_path_array, #resource_array, #resource_model_name, #resource_name, #resources_name

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_instance_variable, #resources_path

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



53
54
55
56
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 53

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

#destroyObject



71
72
73
74
75
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 71

def destroy
  @attachment.destroy
  flash[:notice] = Alchemy.t("File deleted successfully", name: @attachment.name)
  redirect_to alchemy.admin_attachments_path(**search_filter_params)
end

#indexObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 29

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

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



48
49
50
51
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 48

def show
  @assignments = @attachment.related_ingredients.joins(element: :page).merge(PageVersion.draft)
  render :show
end

#updateObject



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

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