Class: Resourcey::Controller
- Inherits:
-
Object
- Object
- Resourcey::Controller
- Defined in:
- lib/resourcey/controller.rb
Instance Method Summary collapse
Methods included from ControllerCollectionScope
Methods included from ControllerFiltering
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/resourcey/controller.rb', line 19 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
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/resourcey/controller.rb', line 40 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
10 11 12 |
# File 'lib/resourcey/controller.rb', line 10 def index render json: serialized_collection(scoped_resources) end |
#show ⇒ Object
14 15 16 17 |
# File 'lib/resourcey/controller.rb', line 14 def show find_resource render json: @resource, serializer: serializer end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resourcey/controller.rb', line 29 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 |