aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorErik Andrejko <eandrejko@gmail.com>2008-10-26 11:46:17 -0500
committerMichael Koziarski <michael@koziarski.com>2008-10-26 19:14:45 +0100
commitef9b6b5cba08f13dcbf7095226b78aaf22df13f7 (patch)
treed9b332eba71925ceb524fbf638369bafe19d8786 /actionpack/lib/action_view/helpers/url_helper.rb
parent2c7abe1b5682d287b19dde5900087908c976109c (diff)
downloadrails-ef9b6b5cba08f13dcbf7095226b78aaf22df13f7.tar.gz
rails-ef9b6b5cba08f13dcbf7095226b78aaf22df13f7.tar.bz2
rails-ef9b6b5cba08f13dcbf7095226b78aaf22df13f7.zip
modified current_page? to ignore extra parameters unless specified in options
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#805 state:committed]
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 7ba42a3b72..2e0eb8766b 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -499,7 +499,7 @@ module ActionView
# True if the current request URI was generated by the given +options+.
#
# ==== Examples
- # Let's say we're in the <tt>/shop/checkout</tt> action.
+ # Let's say we're in the <tt>/shop/checkout?order=desc</tt> action.
#
# current_page?(:action => 'process')
# # => false
@@ -507,6 +507,9 @@ module ActionView
# current_page?(:controller => 'shop', :action => 'checkout')
# # => true
#
+ # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc)
+ # # => false
+ #
# current_page?(:action => 'checkout')
# # => true
#
@@ -515,10 +518,18 @@ module ActionView
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("?")
+ 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.request_uri}"
+ url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
else
- url_string == request.request_uri
+ url_string == request_uri
end
end