Class: RestApiGenerator::ChildResourceController

Inherits:
Object
  • Object
show all
Includes:
ControllerCallbacks, Orderable, Serializable
Defined in:
app/controllers/rest_api_generator/child_resource_controller.rb

Constant Summary

Constants included from Orderable

Orderable::SORT_ORDER

Instance Method Summary collapse

Methods included from Serializable

#index_serializer, #serializer

Methods included from Orderable

#ordering_params

Instance Method Details

#createObject



27
28
29
30
# File 'app/controllers/rest_api_generator/child_resource_controller.rb', line 27

def create
  @resource = resources.create!(resource_created_params)
  render json: serializer(@resource), status: :created
end

#destroyObject



37
38
39
# File 'app/controllers/rest_api_generator/child_resource_controller.rb', line 37

def destroy
  @resource.destroy!
end

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/rest_api_generator/child_resource_controller.rb', line 12

def index
  set_all_resources
  @resources = @resources.filter_resource(params_for_filter) if resource_class.include?(Filterable)
  @resources = @resources.order(ordering_params(params[:sort])) if params[:sort]
  if pagination
    @pagy, @resources = pagy(@resources)
    pagy_headers_merge(@pagy)
  end
  render json: index_serializer(@resources), status: :ok
end

#showObject



23
24
25
# File 'app/controllers/rest_api_generator/child_resource_controller.rb', line 23

def show
  render json: serializer(@resource), status: :ok
end

#updateObject



32
33
34
35
# File 'app/controllers/rest_api_generator/child_resource_controller.rb', line 32

def update
  @resource.update!(resource_updated_params)
  render json: serializer(@resource), status: :ok
end