-
Notifications
You must be signed in to change notification settings - Fork 17
/
assets_controller.rb
118 lines (98 loc) · 2.66 KB
/
assets_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class AssetsController < ApplicationController
before_filter :require_admin!, only: [:destroy]
before_filter :authenticate_user!, except: [:show, :index]
# GET /assets
# GET /assets.json
def index
@artefact = Artefact.find(params[:artefact_id])
@assets = @artefact.assets
respond_to do |format|
format.html # index.html.erb
format.json { render json: @assets }
end
end
# GET /assets/1
# GET /assets/1.json
def show
@asset = Asset.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @asset }
end
end
# GET /assets/new
# GET /assets/new.json
def new
@artefact = Artefact.find(params[:artefact_id])
@asset = @artefact.assets.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @asset }
end
end
# GET /assets/1/edit
def edit
# @artefact = Artefact.find(params[:artefact_id])
@asset = Asset.find(params[:id])
# @asset = Asset.find(params[:id])
end
# POST /assets
# POST /assets.json
def create
@asset = Asset.new(params[:asset])
if @asset.save
respond_to do |format|
format.html do
render json: [@asset.to_jq_upload].to_json,
content_type: 'text/html',
layout: false
end
format.json do
render json: [@asset.to_jq_upload].to_json
end
end
else
render json: [{ error: 'custom_failure' }], status: 304
end
end
# PUT /assets/1
# PUT /assets/1.json
def update
@artefact = Artefact.find(params[:artefact_id])
@asset = @artefact.assets.find(params[:id])
respond_to do |format|
if @asset.update_attributes(asset_params)
format.html { redirect_to artefact_path(@artefact), notice: 'Asset was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @asset.errors, status: :unprocessable_entity }
end
end
end
# DELETE /assets/1
# DELETE /assets/1.json
def destroy
# @artefact = Artefact.find(params[:artefact_id])
# @asset = @artefact.assets.find(params[:id])
@asset = Asset.find(params[:id])
@asset.destroy
respond_to do |format|
format.html { redirect_to root_path }
format.js
end
end
def make_default
@asset = Asset.find(params[:id])
@artefact = Artefact.find(params[:artefact_id])
@artefact.cover = @asset.id
@artefact.save
respond_to do |format|
format.js
end
end
private
def asset_params
params.require(:asset).permit(:artefact_id, :image)
end
end