Class: Plum::Cp::AssetsController
Instance Method Summary
collapse
#plum_asset_file_size, #plum_asset_image_url, #plum_asset_label
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
42
43
|
# File 'app/controllers/plum/cp/assets_controller.rb', line 42
def edit
end
|
#index ⇒ Object
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
|
#new ⇒ Object
19
20
21
|
# File 'app/controllers/plum/cp/assets_controller.rb', line 19
def new
@asset = asset_scope.build
end
|
#update ⇒ Object
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
|