Class: RestApiGenerator::ResourceController

Inherits:
Object
  • Object
show all
Includes:
ControllerCallbacks, Orderable, Serializable
Defined in:
app/controllers/rest_api_generator/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



26
27
28
29
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 26

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

#destroyObject



36
37
38
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 36

def destroy
  @resource.destroy!
end

#indexObject



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

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



22
23
24
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 22

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

#updateObject



31
32
33
34
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 31

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