Can't use ActionDispatch::Request in Rails middleware because path_parameters get lost
357 views
Skip to first unread message
adamc
unread,
Jan 10, 2011, 3:51:23 PM1/10/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
Hi,
I just encountered a bit of an issue where we call request.params of
an ActionDispatch::Request inside a rack middleware right before a
Rails 3.0.3 app. The issue is that the path_parameters never appear
in the parameters hash if you call request.params before the rails
app.
It seems that that the requests.params method memoizes itself in
"action_dispatch.request.parameters" without the parsed
path_parameters. The router seems to properly extract the path params
but never calls request.path_parameters= method which would properly
reset the memoized 'parameters' method.
You can see the code in question here:
# file: action_dispatch/http/parameters.rb
# Returns both GET and POST \parameters in a single hash.
def parameters
@env["action_dispatch.request.parameters"] ||= begin
params = request_parameters.merge(query_parameters)
params.merge!(path_parameters)
encode_params(params).with_indifferent_access
end
end
alias :params :parameters
For now, I've moved to using a Rack::Request object which is a shame
because I had to manually extract out the subdomain and the bug wasn't
very intuitive.