Class: Zobi::ParametersSanitizer
- Inherits:
-
Object
- Object
- Zobi::ParametersSanitizer
- 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
- #initialize(context, canonical_params) ⇒ Sanitizer constructor
-
#params ⇒ ActionController::Parameters
The only public method.
Constructor Details
#initialize(context, canonical_params) ⇒ Sanitizer
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
#params ⇒ ActionController::Parameters
The only public method. Return sanitized parameters.
33 34 35 |
# File 'lib/zobi/parameters_sanitizer.rb', line 33 def params canonical_params.permit resource_type => permitted_fields end |