3

I have a couple of before_actions in my project that will set/merge some additional parameters before calling REST actions. This lets me override some basic gems methods with minimal customization.

However, I have been getting this deprecation warning in the server logs when doing params.merge! :

DEPRECATION WARNING: Method merge is deprecated and will be removed in Rails 5.1, as ActionController::Parameters no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.0.beta2/classes/ActionController/Parameters.html.

I have looked at the documentation link but can't find any obvious method that will let me add a parameter programatically to the params object that will not trigger this warning.

Failure to find a non-hash method means my project will be incompatible with Rails 5.1+

Any help is appreciated

1 Answers1

2

You don't have merge!, but you do have merge. So you should still be able to do in your controller:

params = ActionController::Parameters.new({
         zoo: 'Blijdorp',
         cage: 'monkeys'
     })

params = params.merge(animal: "Bokito")
zjeraar
  • 436
  • 4
  • 11