Class: Alchemy::Admin::AttachmentsController

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

Instance Method Summary collapse

Methods inherited from ResourcesController

#edit, #resource_handler

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #resource_attribute_field_options, #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 ConfigurationMethods

#configuration, #multi_language?, #multi_site?

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 36

def create
  @attachment = Attachment.new(attachment_attributes)
  if @attachment.save
    if in_overlay?
      set_instance_variables
    end
    message = _t('File uploaded succesfully', name: @attachment.name)
    render json: {files: [@attachment.to_jq_upload], growl_message: message}, status: :created
  else
    message = _t('File upload error', error: @attachment.errors[:file].join)
    render json: {files: [@attachment.to_jq_upload], growl_message: message}, status: :unprocessable_entity
  end
end

#destroyObject



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

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

#downloadObject



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

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

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 6

def index
  @attachments = Attachment.all
  if params[:only].present?
    @attachments = @attachments.where("file_mime_type LIKE '%#{params[:only]}%'")
  end
  if params[:except].present?
    @attachments = @attachments.where("file_mime_type NOT LIKE '%#{params[:except]}%'")
  end
  if params[:tagged_with].present?
    @attachments = @attachments.tagged_with(params[:tagged_with])
  end
  @attachments = @attachments.find_paginated(params, 15, sort_order)
  @options = options_from_params
  if in_overlay?
    archive_overlay
  end
end

#newObject



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

def new
  @attachment = Attachment.new
  if in_overlay?
    set_instance_variables
  end
end

#showObject

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



25
26
27
# File 'app/controllers/alchemy/admin/attachments_controller.rb', line 25

def show
  render :show
end

#updateObject



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

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