This project is archived and is in readonly mode.
url_for should not append current params when generating url for same action
Reported by Jakub Suder | June 30th, 2010 @ 03:36 PM
In an empty Rails app with such routes:
resources :users
match "/profiles/:name" => "users#show", :as => :profile
... and such controller:
class UsersController < ApplicationController
def show
if params[:name]
render :text => "ok"
else
redirect_to profile_path(params[:id])
end
end
end
... the profile_path that's generated in the controller includes an extra parameter after a question mark; e.g. if I go to /users/123, I get redirected to /profiles/123?id=123. It should be just /profiles/123. The same helper run from the console (Rails.application.routes.url_helpers.profile_path(123)) returns "/profiles/123", so this happens only in the controller, and apparently only when the target is the same action.
I'm guessing that the problem might be at this line in url_for.rb:
_router.url_for(url_options.merge((options || {}).symbolize_keys))
The url_options that gets merged with options passed in arguments contains :_path_segments with params from current request and that probably causes the ?id=123 in the url...
Comments and changes to this ticket
-
Jakub Suder June 30th, 2010 @ 03:38 PM
Note, the url is generated correctly (without ?id=123) if I force id to be nil, i.e. profile_path(some_id, :id => nil), but I think I shouldn't have to do that.
-
Repository July 3rd, 2010 @ 09:06 AM
- State changed from new to resolved
(from [54250a5bfe6992afaaca6357d3b414e6c49651ba]) Refactor recall parameter normalization [#5021 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/54250a5bfe6992afaaca6357d3b414...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 5021 url_for should not append current params when generating url for same action (from [54250a5bfe6992afaaca6357d3b414e6c49651ba]) Refacto...