public Method

UrlHelper.current_page?(options)

True if the current request URI was generated by the given options.

Examples

Let’s say we’re in the /shop/checkout action.

current_page?(:action => 'process')
# => false

current_page?(:controller => 'shop', :action => 'checkout')
# => true

current_page?(:action => 'checkout')
# => true

current_page?(:controller => 'library', :action => 'checkout')
# => false

Source Code

# File action_view/helpers/url_helper.rb, line 431
def current_page?(options)
  url_string = CGI.escapeHTML(url_for(options))
  request = @controller.request
  if url_string =~ /^\w+:\/\//
    url_string == "#{request.protocol}#{request.host_with_port}#{request.request_uri}"
  else
    url_string == request.request_uri
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.