Module: BetterController::Base

Extended by:
ActiveSupport::Concern
Defined in:
lib/better_controller/base.rb

Overview

Base module that provides core functionality for enhanced controllers

Instance Method Summary collapse

Instance Method Details

#better_controller_handle_error(exception) ⇒ Object

Handle exceptions raised by the controller

Parameters:

  • exception (Exception)

    The exception to handle



42
43
44
# File 'lib/better_controller/base.rb', line 42

def better_controller_handle_error(exception)
  handle_exception(exception)
end

#execute_actionObject

Execute an action with enhanced error handling and response formatting

Parameters:

  • action_block (Proc)

    The block containing the action logic

Returns:

  • (Object)

    The formatted response



23
24
25
26
27
28
29
# File 'lib/better_controller/base.rb', line 23

def execute_action(&)
  log_debug("Executing action: #{action_name}") if respond_to?(:action_name)
  result = instance_eval(&)
  respond_with_success(result)
rescue StandardError => e
  handle_exception(e)
end

#with_transaction(options = {}) ⇒ Object

Helper method to simplify common controller patterns

Parameters:

  • options (Hash) (defaults to: {})

    Options for the action

Returns:

  • (Object)

    The result of the action



34
35
36
37
38
# File 'lib/better_controller/base.rb', line 34

def with_transaction(options = {}, &)
  ActiveRecord::Base.transaction(&)
rescue StandardError => e
  handle_exception(e, options)
end