Class: Alchemy::Admin::AttachmentsController

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

Instance Method Summary collapse

Methods included from UploaderResponses

#failed_uploader_response, #succesful_uploader_response

Methods inherited from ResourcesController

#edit, #new, #resource_handler

Methods included from ResourcesHelper

#contains_relations?, #current_location_params, #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



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

def create
  @attachment = Attachment.new(attachment_attributes)
  if @attachment.save
    render succesful_uploader_response(file: @attachment)
  else
    render failed_uploader_response(file: @attachment)
  end
end

#destroyObject



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

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

#downloadObject



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

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

#indexObject



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

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

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

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

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

  @options = options_from_params
  if in_overlay?
    archive_overlay
  end
end

#showObject

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



31
32
33
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 31

def show
  render :show
end

#updateObject



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

def update
  @attachment.update_attributes(attachment_attributes)
  render_errors_or_redirect(
    @attachment,
    admin_attachments_path(
      per_page: params[:per_page],
      page: params[:page],
      q: params[:q]
    ),
    Alchemy.t("File successfully updated")
  )
end