Class: RestApiGenerator::ResourceController
Constant Summary
Constants included
from Orderable
Orderable::SORT_ORDER
Instance Method Summary
collapse
#index_serializer, #serializer
Methods included from Orderable
#ordering_params
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
36
37
38
|
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 36
def destroy
@resource.destroy!
end
|
#index ⇒ Object
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
@pagy, @resources = pagy(@resources)
(@pagy)
end
render json: index_serializer(@resources), status: :ok
end
|
#show ⇒ Object
22
23
24
|
# File 'app/controllers/rest_api_generator/resource_controller.rb', line 22
def show
render json: serializer(@resource), status: :ok
end
|
#update ⇒ Object
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
|