Module: ActAsJsonapi::Controller

Extended by:
ActiveSupport::Concern
Includes:
Formatter, JSONErrors
Defined in:
lib/act_as_jsonapi/controller.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONErrors

#render_bad_request, #render_conflict_request, #render_error, #render_failed_dependency, #render_forbidden, #render_not_authorized, #render_not_found, #render_service_unavailable, #render_unprocessable_entity, #serializable, #translate_detail_code

Methods included from Formatter

#render_json_api

Class Method Details

.include(base) ⇒ Object



11
12
13
14
15
# File 'lib/act_as_jsonapi/controller.rb', line 11

def self.include(base)
  base.include Pundit

  base.extend ClassMethods
end

Instance Method Details

#destroyObject



43
44
45
46
47
48
# File 'lib/act_as_jsonapi/controller.rb', line 43

def destroy
  authorize _resource

  _resource.destroy
  render_json_api serializer.new(_resource).serializable_hash, status: :no_content
end

#indexObject



17
18
19
20
21
# File 'lib/act_as_jsonapi/controller.rb', line 17

def index
  authorize model

  render_json_api serializer.new(_resources, serializer_options).serializable_hash
end

#showObject



23
24
25
26
27
28
29
# File 'lib/act_as_jsonapi/controller.rb', line 23

def show
  authorize _resource

  render_not_found && return if _resource.kind_of? NilClass

  render_json_api serializer.new(_resource).serializable_hash
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/act_as_jsonapi/controller.rb', line 31

def update
  authorize model

  render_not_found && return if _resource.kind_of? NilClass

  if _resource.update_attributes _resource_params
    render_json_api serializer.new(_resource).serializable_hash, status: :reset_content
  else
    render_unprocessable_entity
  end
end