Module: Response
- Included in:
- Metadatastore::ApplicationController
- Defined in:
- app/controllers/concerns/response.rb
Instance Method Summary collapse
- #controller_namespace ⇒ Object
- #error_response(error, status = 422) ⇒ Object
- #errors_response(errors, status = 422) ⇒ Object
- #json_response(object, status = :ok) ⇒ Object
- #not_found ⇒ Object
Instance Method Details
#controller_namespace ⇒ Object
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_found ⇒ Object
18 19 20 |
# File 'app/controllers/concerns/response.rb', line 18 def not_found render plain: "404 Not Found", status: 404 end |