Class: Repia::BaseController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Repia::BaseController
- Defined in:
- lib/repia/core.rb
Overview
This controller is a base controller for RESTful API. Two primary features:
-
Error (exception) handling
-
Options request handling
Instance Method Summary collapse
-
#options ⇒ Object
Renders a generic OPTIONS response.
-
#render_error(status, msg) ⇒ Object
Renders a single error.
-
#render_errors(status, msgs) ⇒ Object
Renders multiple errors.
Instance Method Details
#options ⇒ Object
Renders a generic OPTIONS response. The actual controller must override this action if desired to have specific OPTIONS handling logic.
57 58 59 60 61 62 63 64 |
# File 'lib/repia/core.rb', line 57 def () # echo back access-control-request-headers if request.headers["Access-Control-Request-Headers"] response["Access-Control-Allow-Headers"] = request.headers["Access-Control-Request-Headers"] end render body: "", status: 200 end |
#render_error(status, msg) ⇒ Object
Renders a single error.
69 70 71 |
# File 'lib/repia/core.rb', line 69 def render_error(status, msg) render json: {errors: [msg]}, status: status end |
#render_errors(status, msgs) ⇒ Object
Renders multiple errors
76 77 78 |
# File 'lib/repia/core.rb', line 76 def render_errors(status, msgs) render json: {errors: msgs}, status: status end |