In Rails 3, params and request.parameters refer to the same object.
With the addition of strong parameters in Rails 4, params now refers to a separate instance of ActionController::Parameters , which is created from request.parameters .
A side effect of this is that after calling params (thereby creating a separate Parameters object), calling request.format= will not update params .
Rails 3:
params # set @_params to request.parameters request.format = "mobile" params[:format] => "mobile"
Rails 4:
params # set @_params to Parameters.new(request.parameters) request.format = "mobile" params[:format] => nil
This is not a technical error, because it is easy for client code to look like request.format instead of params[:format] as a source of truth for this information (and not count on the possibility of being used interchangeably).
But for me it is like a design regression. The presence of params and request.parameters will be the same โexcept forโ, which will lead to an error for us now, and I expect this to cause errors for many developers in the future.
Am I doing it wrong? If so, why is this not a problem, and what should I do differently? Note that the use case that led me along this path is the exact one from the docs for the format = .
source share