method
current_page?
v1.2.6 -
Show latest stable
- Class:
ActionView::Helpers::UrlHelper
current_page?(options)public
True if the current request uri was generated by the given options.
4Notes
/products/1
==== Code example
current_page?(product_path(@product))
# => true
with resources
/products
==== current_page?(products_path) # => true
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
active_link_to helper gem
You should also have a look at https://github.com/twg/active_link_to if you need an 'active' class on your links.