I'm trying to update to Rails 5, I'm getting the following deprecation warning:
DEPRECATION WARNING: Method to_hash 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/classes/ActionController/Parameters.html (called from column_header at /Data/Projects/portal/trunk/app/helpers/application_helper.rb:114)
The line the warning is on looks like this:
link_to(name,
{
action: action_name,
params: params.merge({ order: key, page: nil })
},
{
title: "Sort by this field",
}) +
As you can see, I'm not calling to_hash
. Maybe Rails is. Maybe some other gem is. I have no way to tell, because they didn't think it was worth providing a stack trace. (Pro tip - it usually is worth providing a stack trace!)
So anyway, I followed the link, planning to find a replacement, and the merge
method does not appear to be deprecated, but maybe they simply forgot to document deprecated status, so I can't really be sure.
So what am I supposed to do to clear this?
params.merge
orlink_to
that is callingto_hash
? – Actiumlink_to
calls it but I stepped in to investigate and it goes pretty deep. I managed to verify thaturl_for
calls it, but can't figure out where. So should my view be that they shouldn't be doing that in their own library? I mean, I have passed a Parameters object into something that generates a link from parameters. It seems like it should be OK to do this. – Stereoscopyurl_for
through a param namedparams
, and not directly by passing the params at the top level, as in:link_to(name, {action: action_name, order: key, page: nil}.merge(params)
? – Huneycutt{params: params}
, try{params: params.to_h}
. – Huneycuttto_h
conversion internally. – Reborncaller
to a file of your choosing and then callsuper()
. – Gymnasiarch