Reputation: 2557
I can't seem to get new values added my my params hash. I'm trying to add this actor_id
key to params but this isn't working:
params.merge(:actor_id => 2)
When I use logger.debug before and after the merge I don't see my actor_id
key. How do I add to params
?
Upvotes: 1
Views: 1256
Reputation: 2865
This is because the method merge in ActiveSupport::HashWithIndifferentAccess does not modify the receiver but rather returns a new hash with indifferent access with the result of the merge.
As the comments have suggested use merge! or use update which is an alias.
ActiveController::Parameters inherits from ActiveSupport::HashWithIndifferentAccess
# This method has the same semantics of +update+, except it does not
# modify the receiver but rather returns a new hash with indifferent
# access with the result of the merge.
def merge(hash, &block)
self.dup.update(hash, &block)
end
Upvotes: 1
Reputation: 339
try this
params.merge!(actor_id: 2)
it will modify the params itself as we are using the !
Upvotes: 3