Class: Zobi::ParametersSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/zobi/parameters_sanitizer.rb

Overview

This class responsability is to filter parameters before sending it to the model.

This class is meant to be inherited.

Most of the time, two methods will be overriden: ‘fields` and `translated_fields`.

If you need complex logic based on context of execution (user rights and so on…), you have access to the controller through the ‘context` attr. Meaning, `context.current_user` is possible. And then, you can implement all the `if` possible in the world.

Instance Method Summary collapse

Constructor Details

#initialize(context, canonical_params) ⇒ Sanitizer

Parameters:

  • context (ApplicationController)
  • canonical_params (ActionController::Parameters)


25
26
27
# File 'lib/zobi/parameters_sanitizer.rb', line 25

def initialize(context, canonical_params)
  @context, @canonical_params = context, canonical_params
end

Instance Method Details

#paramsActionController::Parameters

The only public method. Return sanitized parameters.

Returns:

  • (ActionController::Parameters)


33
34
35
# File 'lib/zobi/parameters_sanitizer.rb', line 33

def params
  canonical_params.permit resource_type => permitted_fields
end