Class: Archangel::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Archangel::ApplicationController
- Defined in:
- app/controllers/archangel/application_controller.rb
Overview
Application base controller
Direct Known Subclasses
Instance Method Summary collapse
-
#current_site ⇒ Object
Current site.
-
#render_401_error(exception = nil) ⇒ String
Error 401.
-
#render_404_error(exception = nil) ⇒ String
Error 404.
-
#render_error(path, status, _exception = nil) ⇒ String
Error renderer.
Methods included from Controllers::PaginatableConcern
Instance Method Details
#current_site ⇒ Object
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"
}
58 59 60 |
# File 'app/controllers/archangel/application_controller.rb', line 58 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"
}
76 77 78 |
# File 'app/controllers/archangel/application_controller.rb', line 76 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"
}
94 95 96 |
# File 'app/controllers/archangel/application_controller.rb', line 94 def render_404_error(exception = nil) render_error("archangel/errors/error_404", :not_found, exception) end |
#render_error(path, status, _exception = nil) ⇒ String
Error renderer
Formats
HTML, JSON
Response
{
"status": XYZ,
"error": "Error message"
}
115 116 117 118 119 120 |
# File 'app/controllers/archangel/application_controller.rb', line 115 def render_error(path, status, _exception = nil) respond_to do |format| format.html { render(template: path, status: status) } format.json { render(template: path, status: status, layout: false) } end end |