2

I'm updating to rails 4.2 and get this deprecation warning:

Calling URL helpers with string keys controller, action is deprecated. Use symbols instead.

In the controller I am reusing the params to create some links with the same parameters like this:

@csv_prms = params
@csv_prms[:format] = :csv
...

In the view I do:

= link_to 'CSV', report_path(@csv_prms)

Now I noticed that by default the action and controller in params are strings instead of symbols. Isn't that illogical since they are deprecated to use in URL helpers?

rept
  • 2,086
  • 1
  • 26
  • 44

1 Answers1

3

In general, you should not pass through params between requests (see params.merge and cross site scripting), but instead slice the params you need for your new request and merge the new ones:

@csv_prms = params.slice(:param1, :param2).merge( format: :csv )

This would remove :controller and :action from the params, which shouldn't be required for creating a link at all, because your link_to statements should consistently link to the action you want (instead of letting the user fumble around with parameters to let your site create links to whatever).

BryanH
  • 5,826
  • 3
  • 34
  • 47
  • 1
    Ended up doing: @csv_prms = params.except('controller', 'action') Other params are already checked through permit – rept May 07 '16 at 22:19