This project is archived and is in readonly mode.
![Alexander von Zitzewitz Alexander von Zitzewitz](/images/avatar-large.gif)
current_page? in Rails 2.2.2 delivers wrong results
Reported by Alexander von Zitzewitz | March 11th, 2009 @ 10:51 PM | in 2.x
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
Comments and changes to this ticket
-
Steve Purcell March 27th, 2009 @ 03:42 PM
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)
-
Steve St. Martin April 15th, 2010 @ 11:33 PM
- 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
-
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>