Class: Repia::BaseController

Inherits:
ActionController::Base
  • Object
show all
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

Instance Method Details

#optionsObject

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 options()
  # 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