Migrating an app from Rails 4.2.9 to 5.2.1.
This is latest issue:
$ rails console
/Users/meltemi/rails/myapp/config/initializers/disable_xml_params.rb:3:in `<top (required)>': uninitialized constant ActionDispatch::ParamsParser (NameError)
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:170:in `instrument'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
The offending line of code in an initializer:
# config/initializers/disable_xml_params.rb
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
Rails Guides says:
ActionDispatch::ParamsParser is deprecated and was removed from the middleware stack. To configure the parameter parsers use ActionDispatch::Request.parameter_parsers=. (commit, commit)
So I've tried the following:
ActionDispatch::Request.parameter_parsers.delete(Mime::XML)
But that begets more errors:
$ rails console
/Users/meltemi/rails/myapp/config/initializers/disable_xml_params.rb:3:in `<top (required)>': uninitialized constant Mime::XML (NameError)
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:170:in `instrument'
from /Users/meltemi/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/railties-5.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
Is there a better way to call .delete on that object?
You have to grab the existing values from
parameter_parsers, modify it to suit your needs, then reset the values to your modified values. From the ActionDispatch::Http::Parameters documentation:In your specific case, you should look at the parsers in
original_parsersto see if there is anything to delete. On a simple Rails 5 app that I have handy to look at, the only values I have are:Your app's configuration is likely different, but to answer your question about how to delete a value, this simple version should work:
You may find additional useful information in this answer.