Method: ActionController::Parameters#to_h
- Defined in:
- lib/action_controller/metal/strong_parameters.rb
#to_h(&block) ⇒ Object
Returns a safe ActiveSupport::HashWithIndifferentAccess representation of the parameters with all unpermitted keys removed.
params = ActionController::Parameters.new({
name: "Senjougahara Hitagi",
oddity: "Heavy stone crab"
})
params.to_h
# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
safe_params = params.permit(:name)
safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}
331 332 333 334 335 336 337 |
# File 'lib/action_controller/metal/strong_parameters.rb', line 331 def to_h(&block) if permitted? convert_parameters_to_hashes(@parameters, :to_h, &block) else raise UnfilteredParameters end end |