Class: Resourcey::Controller
Instance Method Summary
collapse
#build_serializer_from_configuration
#scoped_resources
#filtered_resources
Instance Method Details
#create ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/resourcey/controller.rb', line 20
def create
@resource = resource_model.new(resource_params)
if @resource.save
render json: @resource, serializer: serializer, status: :ok
else
render json: { errors: @resource.errors }, status: :bad_request
end
end
|
#destroy ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/resourcey/controller.rb', line 41
def destroy
find_resource
@resource.destroy
if @resource.destroyed?
render json: true, status: :ok
else
render json: { errors: @resource.errors }, status: :bad_request
end
end
|
#index ⇒ Object
11
12
13
|
# File 'lib/resourcey/controller.rb', line 11
def index
render json: serialized_collection(scoped_resources)
end
|
#show ⇒ Object
15
16
17
18
|
# File 'lib/resourcey/controller.rb', line 15
def show
find_resource
render json: @resource, serializer: serializer
end
|
#update ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/resourcey/controller.rb', line 30
def update
find_resource
@resource.assign_attributes(resource_params)
if @resource.save
render json: @resource, serializer: serializer, status: :ok
else
render json: { errors: @resource.errors }, status: :bad_request
end
end
|