Alternative to url_for's deprecated :overwrite_params option

Updated . Posted . Visible to the public.

If you have the following deprecation warning after upgrading to rails >= 2.3.10

DEPRECATION WARNING: The :overwrite_params option is deprecated. Specify all the necessary parameters instead.

that is for example caused by

url_for( :overwrite_params => { :order => 'name', :dir => 'asc' } )

you can fix this by using params.merge {:my_param_to_overwrite => 'foo' }.
To fix the example above the code could look like:

url_for( params.merge { :order => 'name', :dir => 'asc' } )

Note:

link_to uses url_for internally, so you can can use params.merge { ... } as the second parameter of link_to.

Ulrich Berkmüller
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Ulrich Berkmüller to makandra dev (2011-03-15 07:37)