Class: ForestLiana::ResourcesController
Instance Method Summary
collapse
#authenticate_user_from_jwt, #forest_user, papertrail?, #route_not_found, #serialize_model, #serialize_models
Instance Method Details
#create ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 34
def create
creator = ForestLiana::ResourceCreator.new(@resource, params)
creator.perform
if creator.errors
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
creator.errors), status: 400
elsif creator.record.valid?
render serializer: nil,
json: serialize_model(creator.record, include: record_includes)
else
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
creator.record.errors), status: 400
end
end
|
#destroy ⇒ Object
66
67
68
69
70
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 66
def destroy
@resource.destroy(params[:id])
head :no_content
end
|
#index ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 16
def index
getter = ForestLiana::ResourcesGetter.new(@resource, params)
getter.perform
render serializer: nil, json: serialize_models(getter.records,
include: includes(getter),
count: getter.count,
params: params)
end
|
#show ⇒ Object
26
27
28
29
30
31
32
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 26
def show
getter = ForestLiana::ResourceGetter.new(@resource, params)
getter.perform
render serializer: nil, json:
serialize_model(getter.record, include: includes(getter))
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/controllers/forest_liana/resources_controller.rb', line 50
def update
updater = ForestLiana::ResourceUpdater.new(@resource, params)
updater.perform
if updater.errors
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
updater.errors), status: 400
elsif updater.record.valid?
render serializer: nil,
json: serialize_model(updater.record, include: record_includes)
else
render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
updater.record.errors), status: 400
end
end
|