This project is archived and is in readonly mode.

#5021 ✓resolved
Jakub Suder

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

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

Pages