Class: Archangel::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Controllers::ActionableConcern, Controllers::PaginatableConcern, Controllers::ThemableConcern
Defined in:
app/controllers/archangel/application_controller.rb

Overview

Application base controller

Instance Method Summary collapse

Methods included from Controllers::PaginatableConcern

#page_num, #per_page

Methods included from Controllers::ActionableConcern

#action, #collection_action?, #member_action?

Instance Method Details

#current_siteObject

Current site

Response

{
  "id": 123,
  "name": "Site Name",
  "theme": "my_theme",
  "locale": "en",
  "logo": {
    "url": "/uploads/file.png",
    "large": {
      "url": "/uploads/large_file.png"
    },
    "medium": {
      "url": "/uploads/medium_file.png"
    },
    "small": {
      "url": "/uploads/small_file.png"
    },
    "tiny": {
      "url": "/uploads/tiny_file.png"
    }
  },
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}

59
60
61
# File 'app/controllers/archangel/application_controller.rb', line 59

def current_site
  @current_site ||= Archangel::Site.current
end

#render_401_error(exception = nil) ⇒ String

Error 401

Render a 401 (unauthorized) error response

Response

{
  "status": 401,
  "error": "Access is denied due to invalid credentials"
}

Parameters:

  • exception (Object) (defaults to: nil)

    error object

Returns:

  • (String)

    response


77
78
79
# File 'app/controllers/archangel/application_controller.rb', line 77

def render_401_error(exception = nil)
  render_error("archangel/errors/error_401", :unauthorized, exception)
end

#render_404_error(exception = nil) ⇒ String

Error 404

Render a 404 (not found) error response

Response

{
  "status": 404,
  "error": "Page not found"
}

Parameters:

  • exception (Object) (defaults to: nil)

    error object

Returns:

  • (String)

    response


95
96
97
# File 'app/controllers/archangel/application_controller.rb', line 95

def render_404_error(exception = nil)
  render_error("archangel/errors/error_404", :not_found, exception)
end

#render_error(path, status, _exception) ⇒ String

Error renderer

Formats

HTML, JSON

Response

{
  "status": XYZ,
  "error": "Error message"
}

Parameters:

  • path (String)

    error template path

  • status (String, Symbol)

    response status code

  • _exception (Object)

    error object

Returns:

  • (String)

    response


116
117
118
119
120
121
# File 'app/controllers/archangel/application_controller.rb', line 116

def render_error(path, status, _exception)
  respond_to do |format|
    format.html { render(template: path, status: status) }
    format.json { render(template: path, status: status, layout: false) }
  end
end