W3cubDocs

/Padrino

Module: Padrino::ParamsProtection::InstanceMethods

Instance Method Summary

Instance Method Details

#filter_params!(params, allowed_params) ⇒ Object

Filters a hash of parameters leaving only allowed ones and possibly typecasting and processing the others.

Examples:

filter_params!( { "a" => "1", "b" => "abc", "d" => "drop" },
                { "a" => Integer, "b" => true } )
# => { "a" => 1, "b" => "abc" }
filter_params!( { "id" => "", "child" => { "name" => "manny" } },
                { "id" => Integer, "child" => { "name" => proc{ |v| v.camelize } } } )
# => { "id" => nil, "child" => { "name" => "Manny" } }
filter_params!( { "a" => ["1", "2", "3"] },
                { "a" => true } )
# => { "a" => ["1", "2", "3"] }
filter_params!( { "persons" => {"p-1" => { "name" => "manny", "age" => "50" }, "p-2" => { "name" => "richard", "age" => "50" } } },
                { "persons" => { "name" => true } } )
# => { "persons" => {"p-1" => { "name" => "manny" }, "p-2" => { "name" => "richard" } } }

Parameters:

  • params (Hash) — Parameters to filter. Warning: this hash will be changed by deleting or replacing its values.
  • allowed_params (Hash) — A hash of allowed keys and value classes or processing procs. Supported scalar classes are: Integer (empty string is cast to nil).

#original_params ⇒ Object

Returns the original unfiltered query parameters hash.