instance method
current_page?
Ruby on Rails 3.2.22.5
Since v2.2.3Signature
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?order=desc action.
current_page?(:action => 'process') # => false current_page?(:controller => 'shop', :action => 'checkout') # => true current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc') # => false current_page?(:action => 'checkout') # => true current_page?(:controller => 'library', :action => 'checkout') # => false
Let’s say we’re in the /shop/checkout?order=desc&page=1 action.
current_page?(:action => 'process') # => false current_page?(:controller => 'shop', :action => 'checkout') # => true current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '1') # => true current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc', :page => '2') # => false current_page?(:controller => 'shop', :action => 'checkout', :order => 'desc') # => false current_page?(:action => 'checkout') # => true current_page?(:controller => 'library', :action => 'checkout') # => false
Let’s say we’re in the /products action with method POST in case of invalid product.
current_page?(:controller => 'product', :action => 'index') # => false
Parameters
-
optionsreq
Source
# File actionpack/lib/action_view/helpers/url_helper.rb, line 588
def current_page?(options)
unless request
raise "You cannot use helpers that need to determine the current " \
"page unless your view context provides a Request object " \
"in a #request method"
end
return false unless request.get?
url_string = url_for(options)
# 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.fullpath
else
request_uri = request.path
end
if url_string =~ /^\w+:\/\//
url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
else
url_string == request_uri
end
end
Defined in actionpack/lib/action_view/helpers/url_helper.rb line 588
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::UrlHelper