Module: Encore::Helpers::ControllerHelper

Defined in:
lib/encore/helpers/controller_helper.rb

Constant Summary collapse

HTTP_ERROR_STATUS_CODE =
422
HTTP_SUCCESS_CODE =
200
HTTP_SUCCESS_CREATED_CODE =
201

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inject_into_action_controllerObject

Inject itself into the ActionController::Base class



9
10
11
# File 'lib/encore/helpers/controller_helper.rb', line 9

def self.inject_into_action_controller
  ::ActionController::Base.send :include, self
end

Instance Method Details

#process!(entity) ⇒ Object

Save the entity and return a JSON response



14
15
16
17
18
19
20
21
22
23
# File 'lib/encore/helpers/controller_helper.rb', line 14

def process!(entity)
  error_status = HTTP_ERROR_STATUS_CODE
  success_status = success_status_code_from_entity(entity)

  if entity.save
    render json: entity, status: success_status
  else
    render json: { errors: entity.errors }, status: error_status
  end
end