Open glaucocustodio opened 7 years ago
Calling .to_h
we lose class name display and the permitted: true/false
for each ActionController::Parameters object in the hash.
"licensings_attributes"=><ActionController::Parameters {"0"=><ActionController::Parameters {"license_number"=>"", "license_id"=>"1", "expiration_date"=>""} permitted: true>}
"licensings_attributes" => {
"0" => {
"license_number" => "",
"license_id" => "1",
"expiration_date" => ""
}
[Exception] DEPRECATION WARNING: #to_hash unexpectedly ignores parameter filtering, and will change to enforce it in Rails 5.1. Enable
raise_on_unfiltered_parameters
to respect parameter filtering, which is the default in new applications. For the existing deprecated behaviour, call #to_unsafe_h instead.
what's the move here? breaking my rails 5.1 project
@sebbean you're very welcome to submit a patch! :)
@imajes actually turns out to be working just fine! I just wasn't sending Content-Type: app/json so it wasn't parsing the params correctly. Was assuming form-data, thus params where essentially null.
Still seems to be a weird error for that case tho.
To circumvent:
*** ActionController::UnfilteredParameters Exception: unable to convert unpermitted parameters to hash
... you can use this hack: ap params.to_enum.to_h
.
+1 for ap params
@janwerkhoven wrote:
... you can use this hack: ap params.to_enum.to_h
That works if you want it the display to be on STDOUT -- alas, if I instead want that pretty-print to be recorded to the debug log, and I try Rails.logger.debug ("#{params.to_enum.to_h.ai}")
, it throws an error:
ActionController::UnfilteredParameters - unable to convert unpermitted parameters to hash:
app/controllers/reports/exports_controller.rb:15:in `create'
app/controllers/application_controller.rb:334:in `block in wrap_in_user_time_zone'
app/controllers/application_controller.rb:334:in `wrap_in_user_time_zone'
app/middleware/healthcheck_middleware.rb:21:in `call'
@philCryoport You can probably work around that with a .permit!
Thank you! That worked!
As of Rails 5 (https://github.com/rails/rails/pull/20868) calling
params
in a controller does not return a hash but aActionController::Parameters
.If we do
ap params
on Rails 5, we don't leverage this gem, we gotta doap params.to_h
.Should we implement calling
to_h
in any instance ofActionController::Parameters
?Thank you.