Class: ForestLiana::AssociationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forest_liana/associations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user_from_jwt, #forest_user, papertrail?, #route_not_found, #serialize_model, #serialize_models

Instance Method Details

#associateObject



33
34
35
36
37
38
# File 'app/controllers/forest_liana/associations_controller.rb', line 33

def associate
  associator = HasManyAssociator.new(@resource, @association, params)
  associator.perform

  head :no_content
end

#dissociateObject



40
41
42
43
44
45
# File 'app/controllers/forest_liana/associations_controller.rb', line 40

def dissociate
  dissociator = HasManyDissociator.new(@resource, @association, params)
  dissociator.perform

  head :no_content
end

#indexObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/forest_liana/associations_controller.rb', line 11

def index
  getter = HasManyGetter.new(@resource, @association, params)
  getter.perform

  respond_to do |format|
    format.json { render_jsonapi(getter) }
    format.csv { render_csv(getter, @association.klass) }
  end
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/forest_liana/associations_controller.rb', line 21

def update
  updater = BelongsToUpdater.new(@resource, @association, params)
  updater.perform

  if updater.errors
    render serializer: nil, json: JSONAPI::Serializer.serialize_errors(
      updater.errors), status: 422
  else
    head :no_content
  end
end