Module: Response

Included in:
Launchpad::ApplicationController
Defined in:
app/controllers/concerns/response.rb

Instance Method Summary collapse

Instance Method Details

#controller_namespaceObject



22
23
24
# File 'app/controllers/concerns/response.rb', line 22

def controller_namespace
  self.class.module_parent.name.split("::").last.underscore
end

#error_response(error, status = 422) ⇒ Object



8
9
10
11
# File 'app/controllers/concerns/response.rb', line 8

def error_response(error, status=422)
  data = "#{controller_namespace}.#{error}"
  json_response({errors: [data]}, status)
end

#errors_response(errors, status = 422) ⇒ Object



13
14
15
16
# File 'app/controllers/concerns/response.rb', line 13

def errors_response(errors, status=422)
  data = errors.map { |error| "#{controller_namespace}.#{error}" }
  json_response({errors: data}, status)
end

#json_response(object, status = :ok) ⇒ Object



4
5
6
# File 'app/controllers/concerns/response.rb', line 4

def json_response(object, status=:ok)
  render json: object, status: status
end

#not_foundObject



18
19
20
# File 'app/controllers/concerns/response.rb', line 18

def not_found
  render plain: "404 Not Found", status: 404
end