Module: Apique::Editable

Extended by:
ActiveSupport::Concern
Includes:
Pickable
Defined in:
lib/apique/editable.rb

Overview

Basic functional for creating, updating, and destroying records.

Instance Method Summary collapse

Methods included from Pickable

#show

Instance Method Details

#createObject

A resource is already built by CanCan according to load_resource params in the current controller. POST /api/plural_resource_name



19
20
21
22
23
24
25
# File 'lib/apique/editable.rb', line 19

def create
  if get_resource.save
    render json: get_resource, status: :created
  else
    render json: {errors: get_resource.errors}
  end
end

#destroyObject

DELETE /api/plural_resource_name/id



37
38
39
40
41
42
43
44
# File 'lib/apique/editable.rb', line 37

def destroy
  get_resource.destroy
  unless get_resource.errors.present?
    on_destroy
  else
    render json: {errors: get_resource.errors}
  end
end

#updateObject

PATCH/PUT /api/plural_resource_name/id



28
29
30
31
32
33
34
# File 'lib/apique/editable.rb', line 28

def update
  if get_resource.update(apique_update_params)
    render json: get_resource
  else
    render json: {errors: get_resource.errors}
  end
end