Class: Securial::ApplicationController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/securial/application_controller.rb

Overview

ApplicationController

This is the base controller for the Securial engine, inheriting from ActionController::API. and provides common functionality for all Securial controllers, including:

- Custom view path configuration
- Common exception handling for API responses
- Standardized error rendering

All other controllers in the Securial engine inherit from this controller to ensure consistent behavior across the API.

Instance Method Summary collapse

Instance Method Details

#render_400(exception) ⇒ void (private)

This method returns an undefined value.

Renders a standardized 400 Bad Request JSON response.

Called automatically when an ActionController::ParameterMissing exception is raised, providing the client with information about the missing parameter.

Parameters:

  • exception (ActionController::ParameterMissing)

    The exception raised for missing parameters



43
44
45
46
47
48
# File 'app/controllers/securial/application_controller.rb', line 43

def render_400(exception)
  render status: :bad_request, json: {
    errors: [exception.message],
    instructions: "Please ensure all required parameters are provided and formatted correctly.",
   }
end

#render_404void (private)

This method returns an undefined value.

Renders a standardized 404 Not Found JSON response.

Called automatically when an ActiveRecord::RecordNotFound exception is raised, ensuring consistent error responses across the API.

Parameters:

  • exception (ActiveRecord::RecordNotFound)

    The exception raised when a record is not found



29
30
31
32
33
34
# File 'app/controllers/securial/application_controller.rb', line 29

def render_404
  render status: :not_found, json: {
    errors: ["Record not found"],
    instructions: "Please check the requested resource and try again.",
  }
end