In rails 4, I can merge! StrongParams, but since rails 5 (beta1) merge! is not available. Which is the best way to do that in a controller
params = ActionController::Parameters.new({
name: 'Francesco',
age: 22,
role: 'admin'
})
params.merge!(city: "Los Angeles")
As far as I can see from the source code, you have merge not merge!. In other words, it doesn't seem to be possible to modify the hash in place.
The following code will work:
params = ActionController::Parameters.new({
name: 'Francesco',
age: 22,
role: 'admin'
})
params = params.merge(city: "Los Angeles")
params.merge!(city: "Los Angeles") works with Rails5.0.1

In Rails 5: ActionController::Parameters Now Returns an Object Instead of a Hash.
so you must use params.permit(:city).to_h to access city.
For more details how ActionController::Parameters works in Rails5?
Ref: http://www.rortuts.com/ruby-on-rails/rails5-actioncontrollerparameters/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With