class Apes::Controller
A ready to use controller for JSON API applications.
@attribute [r] current_account
@return [Object] The current account making the request
@attribute [r] cursor
@return [Apes::PaginationCursor] The pagination cursor for this request.
@attribute [r] request_cursor
@return [Apes::PaginationCursor] The original pagination cursor sent from the client.
Attributes
current_account[R]
cursor[R]
request_cursor[R]
Public Instance Methods
default_url_options()
click to toggle source
Returns the default URL options for this request. It ensures that the host is always included and that is set properly in development mode.
@return [Hash] Default URL options for the request.
# File lib/apes/controller.rb, line 38 def default_url_options rv = {only_path: false} rv = {host: request_source_host} if Apes::RuntimeConfiguration.development? rv end
handle_cors()
click to toggle source
Tiny handle to handle CORS OPTIONS requests. It just renders nothing as headers are handle in Apes::Concerns::Response
module.
To enable this route, add the following to the routes.rb:
# This is to enable AJAX cross domain match '*path', to: 'application#handle_cors', via: :options
# File lib/apes/controller.rb, line 50 def handle_cors render(nothing: true, status: :no_content) end
render_error(status, errors)
click to toggle source
Default handler to render errors.
@param status [Symbol|Fixnum] The HTTP error code to return. @param errors [Array] The list of occurred errors.
# File lib/apes/controller.rb, line 58 def render_error(status, errors) @errors = errors status_code = status.is_a?(Fixnum) ? status : Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(status.to_sym, 500) render("errors/#{status_code}", status: status) end