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.

This project is archived and is in readonly mode.

current_page? in Rails 2.2.2 delivers wrong results

#2218

I recently upgraded my rails app from 2.1.1 to 2.2.2 and now the current_page function sometimes delivers wrong results. It worked fine on the old site.

The function returns true if the current uri is /users?filter=x and you pass in /users (options are empty). I believe the result should be false in this case.

here is the current code:

  def current_page?(options)
    url_string = CGI.escapeHTML(url_for(options))
    request = @controller.request
    # We ignore any extra parameters in the request_uri if the 
    # submitted url doesn't have any either.  This lets the function
    # work with things like ?order=asc 
    if url_string.index("?") # <<<< This test seems to be the problem <<<<
      request_uri = request.request_uri
    else
      request_uri = request.request_uri.split('?').first
    end
    if url_string =~ /^\w+:\/\//
      url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
    else
      url_string == request_uri
    end
  end

If I ommit the marked test and do never split the request_uri everything works fine.

I would deliver a patch if I knew how to do it.

Thx for any help

Reported by Alexander von Zitzewitz · March 11th, 2009 @ 10:51 PM

State: wontfix
Milestone: 2.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Steve Purcell
    Steve Purcell

    Hi Alexander,

    The behaviour appears to be intentional: see the tests for #current_url.

    I think the idea is that "current_page" considers two URLs to be the same page if they both refer to the same RESTful object (or set of objects), regardless of additional query parameters. So "/users?filter=x" is still the "user list" page, just as for "/users". Two different "pages" in this sense would therefore have different routes.

    In your case, if you have conditional display logic depending on whether or not a filter is currently applied to the "/users" page, you should probably look at "request.params[:filter]" within the display code, or set a @filter variable in the controller, which you can then inspect in the view to decide what to do.

    (Suggested resolution for this ticket: invalid / won't fix)

    March 27th, 2009 @ 03:42 PM

  2. Steve St. Martin
    Steve St. Martin
    • Assigned user set to Ryan Bigg

    Agreed, rails is continues to focus more and more on RESTful design, this behavior is intended. Can be marked as wontfix

    April 15th, 2010 @ 11:33 PM

  3. Ryan Bigg
    Ryan Bigg
    • State changed from new to wontfix

    Agreed.

    April 15th, 2010 @ 11:35 PM