Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

url_for should not append current params when generating url for same action

#5021

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...

Reported by Jakub Suder · June 30th, 2010 @ 03:36 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Jakub Suder
    Jakub Suder

    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.

    June 30th, 2010 @ 03:38 PM

  2. Repository