Class: Plum::Cp::AssetsController

Inherits:
BaseController show all
Includes:
AssetsHelper
Defined in:
app/controllers/plum/cp/assets_controller.rb

Instance Method Summary collapse

Methods included from AssetsHelper

#plum_asset_file_size, #plum_asset_image_url, #plum_asset_label

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/plum/cp/assets_controller.rb', line 23

def create
  @asset = asset_scope.build(asset_params)

  if @asset.save
    respond_to do |format|
      format.html { redirect_to cp_assets_path, notice: "Asset uploaded" }
      format.json { render json: asset_json(@asset), status: :created }
    end
  else
    respond_to do |format|
      format.html do
        @assets = asset_scope.order(created_at: :desc)
        render :index, status: :unprocessable_entity
      end
      format.json { render json: { errors: @asset.errors.full_messages }, status: :unprocessable_entity }
    end
  end
end

#destroyObject



53
54
55
56
# File 'app/controllers/plum/cp/assets_controller.rb', line 53

def destroy
  @asset.destroy
  redirect_to cp_assets_path, notice: "Asset deleted"
end

#editObject



42
43
# File 'app/controllers/plum/cp/assets_controller.rb', line 42

def edit
end

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/plum/cp/assets_controller.rb', line 9

def index
  @assets = asset_scope.order(created_at: :desc)
  @asset = asset_scope.build

  respond_to do |format|
    format.html
    format.json { render json: @assets.map { |asset| asset_json(asset) } }
  end
end

#newObject



19
20
21
# File 'app/controllers/plum/cp/assets_controller.rb', line 19

def new
  @asset = asset_scope.build
end

#updateObject



45
46
47
48
49
50
51
# File 'app/controllers/plum/cp/assets_controller.rb', line 45

def update
  if @asset.update(asset_params)
    redirect_to cp_assets_path, notice: "Asset updated"
  else
    render :edit, status: :unprocessable_entity
  end
end