Class: Archangel::ApplicationController

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

Overview

Application base controller

Instance Method Summary collapse

Methods included from PaginatableConcern

#page_num, #per_page

Methods included from ActionableConcern

#action, #collection_action?, #edit_action?, #index_action?, #member_action?, #new_action?, #restful_action?, #save_action?, #show_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"
    }
  },
  "content": "</p>Content of the Widget</p>",
  "template_id": 123,
  "deleted_at": null,
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}


62
63
64
# File 'app/controllers/archangel/application_controller.rb', line 62

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



80
81
82
# File 'app/controllers/archangel/application_controller.rb', line 80

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



98
99
100
# File 'app/controllers/archangel/application_controller.rb', line 98

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



119
120
121
122
123
124
# File 'app/controllers/archangel/application_controller.rb', line 119

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