Class: ForestLiana::AssociationsController
Instance Method Summary
collapse
#authenticate_user_from_jwt, #deactivate_count_response, #forest_user, #internal_server_error, papertrail?, #serialize_model, #serialize_models
#route_not_found
Instance Method Details
#associate ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/forest_liana/associations_controller.rb', line 60
def associate
begin
associator = HasManyAssociator.new(@resource, @association, params)
associator.perform
head :no_content
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Associate error: #{error}\n#{format_stacktrace(error)}"
internal_server_error
end
end
|
#count ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/forest_liana/associations_controller.rb', line 27
def count
find_resource
find_association
begin
getter = HasManyGetter.new(@resource, @association, params, forest_user)
getter.count
render serializer: nil, json: { count: getter.records_count }
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Index Count error: #{error}\n#{format_stacktrace(error)}"
internal_server_error
end
end
|
#dissociate ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/controllers/forest_liana/associations_controller.rb', line 73
def dissociate
begin
dissociator = HasManyDissociator.new(@resource, @association, params, forest_user)
dissociator.perform
head :no_content
rescue ActiveRecord::RecordNotDestroyed => error
render json: { errors: [{ status: :bad_request, detail: error.message }] }, status: :bad_request
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Dissociate error: #{error}\n#{format_stacktrace(error)}"
internal_server_error
end
end
|
#index ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/forest_liana/associations_controller.rb', line 11
def index
begin
getter = HasManyGetter.new(@resource, @association, params, forest_user)
getter.perform
respond_to do |format|
format.json { render_jsonapi(getter) }
format.csv { render_csv(getter, @association.klass) }
end
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Index error: #{error}\n#{format_stacktrace(error)}"
internal_server_error
end
end
|
#update ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/forest_liana/associations_controller.rb', line 42
def update
begin
updater = BelongsToUpdater.new(@resource, @association, params)
updater.perform
if updater.errors
render serializer: nil, json: ForestAdmin::JSONAPI::Serializer.serialize_errors(
updater.errors), status: 422
else
head :no_content
end
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Update error: #{error}\n#{format_stacktrace(error)}"
internal_server_error
end
end
|