method
current_page?
![Very extensive documentation Importance_5](https://d2vfyqvduarcvs.cloudfront.net/images/importance_5.png?1349367920)
v4.2.9 -
Show latest stable
-
4 notes -
Class: ActionView::Helpers::UrlHelper
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (-1)
- 2.0.3 (20)
- 2.1.0 (0)
- 2.2.1 (6)
- 2.3.8 (38)
- 3.0.0 (0)
- 3.0.9 (-4)
- 3.1.0 (0)
- 3.2.1 (10)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (6)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (-15)
- 5.1.7 (5)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
current_page?(options)
public
True if the current request URI was generated by the given options.
Examples
Let’s say we’re in the http://www.example.com/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 current_page?('http://www.example.com/shop/checkout') # => true current_page?('/shop/checkout') # => true
Let’s say we’re in the http://www.example.com/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 http://www.example.com/products action with method POST in case of invalid product.
current_page?(controller: 'product', action: 'index') # => false
Register or
log in
to add new notes.
bansalakhil -
January 16, 2009
qoobaa -
January 2, 2009
Finist -
December 11, 2008
tordans -
November 4, 2011
![Default_avatar_30](https://www.gravatar.com/avatar/174330d280860a6ad77a6d15dd7fabe1?default=http://apidock.com/images/default_avatar_30.png&size=30)
7 thanks
![Default_avatar_30](https://www.gravatar.com/avatar/7fe73b5d5a08f4de9374840fb7d79702?default=http://apidock.com/images/default_avatar_30.png&size=30)
3 thanks
current_action? and current_controller?
I use them in link_unless_current_controller helper.
def current_action?(options) url_string = CGI.escapeHTML(url_for(options)) params = ActionController::Routing::Routes.recognize_path(url_string, :method => :get) params[:controller] == @controller.controller_name && params[:action] == @controller.action_name end def current_controller?(options) url_string = CGI.escapeHTML(url_for(options)) params = ActionController::Routing::Routes.recognize_path(url_string, :method => :get) params[:controller] == @controller.controller_name end
![Default_avatar_30](https://www.gravatar.com/avatar/c1c6f92d7a5b966d5c19928005ff546b?default=http://apidock.com/images/default_avatar_30.png&size=30)
3 thanks
![Default_avatar_30](https://www.gravatar.com/avatar/ea3ff1b44d6b6c958e1b5283ba7a1132?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
active_link_to helper gem
You should also have a look at github.com/twg/active_link_to if you need an ‘active’ class on your links.