Class: Backend::AssetsController

Inherits:
BaseController
  • Object
show all
Includes:
Concerns::PaginationController
Defined in:
app/controllers/backend/assets_controller.rb

Instance Method Summary collapse

Methods included from Concerns::PaginationController

#page_number, #paginate, #per_page

Methods inherited from BaseController

#breadcrumb, #current_admin, #default_app_locale, #translate_notice

Methods included from Udongo::Cryptography

#crypt

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/backend/assets_controller.rb', line 24

def create
  @model = Asset.new allowed_params

  if @model.save
    redirect_to backend_assets_path, notice: translate_notice(:added, :file)
  else
    render :new
  end
end

#destroyObject



42
43
44
45
# File 'app/controllers/backend/assets_controller.rb', line 42

def destroy
  @model.destroy if @model.deletable?
  redirect_to backend_assets_path, notice: translate_notice(:deleted, :file)
end

#indexObject



7
8
9
10
# File 'app/controllers/backend/assets_controller.rb', line 7

def index
  @search = Asset.ransack params[:q]
  @assets = @search.result(distinct: true).order('id DESC').page(page_number).per_page(per_page)
end

#newObject



20
21
22
# File 'app/controllers/backend/assets_controller.rb', line 20

def new
  @model = Asset.new
end

#showObject



12
13
14
15
16
17
18
# File 'app/controllers/backend/assets_controller.rb', line 12

def show
  send_data(
    File.open(@model.filename.path).read,
    filename: @model.actual_filename,
    type: @model.content_type
  )
end

#updateObject



34
35
36
37
38
39
40
# File 'app/controllers/backend/assets_controller.rb', line 34

def update
  if @model.update_attributes allowed_params
    redirect_to backend_assets_path, notice: translate_notice(:edited, :file)
  else
    render :edit
  end
end