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



46
47
48
49
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 46

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

#destroyObject



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

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 22

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

  @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.



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

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

#updateObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 51

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