Module: Api::Resources

Extended by:
ActiveSupport::Concern
Included in:
ProgramsController, ProposalsController, SpacesController
Defined in:
app/controllers/concerns/api/resources.rb

Instance Method Summary collapse

Instance Method Details

#add_resourceObject



17
18
19
20
21
22
23
24
25
# File 'app/controllers/concerns/api/resources.rb', line 17

def add_resource
  @document = Document.new(resource_params)
  if @document.save
    @obj.resources << @document
    render json: @obj.resources, each_serializer: Api::DocumentSerializer, status: :created
  else
    render json: @document.errors, status: :unprocessable_entity
  end
end

#index_resourceObject



13
14
15
# File 'app/controllers/concerns/api/resources.rb', line 13

def index_resource
  render json: @obj.resources, each_serializer: Api::DocumentSerializer, status: :ok
end

#remove_resourceObject



36
37
38
39
40
41
42
# File 'app/controllers/concerns/api/resources.rb', line 36

def remove_resource
  if @document.destroy
    render json: @obj.resources, each_serializer: Api::DocumentSerializer, status: :ok
  else
    render json: { "error": 'Something went wrong...' }, status: :unprocessable_entity
  end
end

#update_resourceObject



27
28
29
30
31
32
33
34
# File 'app/controllers/concerns/api/resources.rb', line 27

def update_resource
  if @document.update(resource_params)
    @obj.resources << @document
    render json: @obj.resources, each_serializer: Api::DocumentSerializer, status: :created
  else
    render json: @document.errors, status: :unprocessable_entity
  end
end