Module: ActionController::Params
- Defined in:
- runtime/action_controller/params.rb,
runtime/action_controller/params.rbs
Overview
Narrowing accessors over the request-params tree.
The request's params are a plain Hash here, so the counterpart of
ActionController::Parameters (require, permit) is a set of module
functions over that Hash — require cannot be a method on it: the call
would reach Kernel's private require instead.
The narrowing is is_a? in narrowing position (the branch answers the
narrowed value), the shape the compiler already handles.
Class Method Summary collapse
-
.permit(source, filters) ⇒ Hash{Symbol => untyped}
the strong-parameters filter over the plain request-params Hash: only the named keys survive, each value shaped by its filter.
-
.permitted(acc, params, key, name) ⇒ Hash
one key of a permitted set: the scalar the request carried for
keyis added toaccundername, and left out otherwise, so a model write leaves that attribute alone. -
.provided(sub, key) ⇒ Boolean
did the request carry a usable value for
key? A blank string counts as provided (permitkeeps a blank,compactdrops only an explicit nil); an absent key, a JSON null, and a non-scalar do not. -
.require_key(params, key) ⇒ Object
the value the request carried for
key, turning a missing or blank parameter into a 400 instead of a nil that fails somewhere later. -
.str(sub, key, fallback) ⇒ String
the scalar under
key, orfallbackwhen the key is absent or holds a nested hash or array. -
.sub(params, key) ⇒ Hash
the nested resource hash the params carry under
key({"article" => {"title" => …}}).
Class Method Details
.permit(source, filters) ⇒ Hash{Symbol => untyped}
the strong-parameters filter over the plain request-params Hash: only the named keys survive, each value shaped by its filter.
A Symbol names a scalar key and keeps its value when truthy; {}
keeps a nested Hash as-is (JSON leaves are already permitted); an
Array keeps only the listed keys of a Hash, or maps each Hash
element of an Array through the same list and passes non-Hash
elements through. Unknown top-level keys and unshaped values are
dropped.
The result's top-level keys are Symbols (call sites read them that way); nested keys keep the objects the request carried.
136 |
# File 'runtime/action_controller/params.rb', line 136
def self.permit: (Hash[untyped, untyped], untyped) -> Hash[Symbol, untyped]
|
.permitted(acc, params, key, name) ⇒ Hash
one key of a permitted set: the scalar the request carried for key is
added to acc under name, and left out otherwise, so a model write
leaves that attribute alone.
81 |
# File 'runtime/action_controller/params.rb', line 81
def self.permitted: (Hash[Symbol, String], Hash[String, untyped], String, Symbol) -> Hash[Symbol, String]
|
.provided(sub, key) ⇒ Boolean
did the request carry a usable value for key? A blank string counts as
provided (permit keeps a blank, compact drops only an explicit nil);
an absent key, a JSON null, and a non-scalar do not.
Named without a ? on purpose — this is generated code, so
portability beats the Ruby idiom.
100 |
# File 'runtime/action_controller/params.rb', line 100
def self.provided: (Hash[String, untyped], String) -> bool
|
.require_key(params, key) ⇒ Object
the value the request carried for key, turning a missing or blank
parameter into a 400 instead of a nil that fails somewhere later. sub is
the forgiving counterpart (absent yields {}).
59 |
# File 'runtime/action_controller/params.rb', line 59
def self.require_key: (Hash[String, untyped], String) -> untyped
|
.str(sub, key, fallback) ⇒ String
the scalar under key, or fallback when the key is absent or holds a
nested hash or array.
39 |
# File 'runtime/action_controller/params.rb', line 39
def self.str: (Hash[String, untyped], String, String) -> String
|
.sub(params, key) ⇒ Hash
the nested resource hash the params carry under key ({"article" => {"title" => …}}).
21 |
# File 'runtime/action_controller/params.rb', line 21
def self.sub: (Hash[String, untyped], String) -> Hash[String, untyped]
|