Last active
August 29, 2015 13:56
-
-
Save zyphlar/8998640 to your computer and use it in GitHub Desktop.
Helper for generating menu links (inside an <li> tag, with an active class if we're on the current page)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#usage: <%= li_link_to 'Home', home_path if (can? :read, Home) %> | |
def li_link_to(name = nil, options = nil, html_options = nil, &block) | |
html_options, options, name = options, name, block if block_given? | |
options ||= {} | |
html_options = convert_options_to_data_attributes(options, html_options) | |
url = url_for(options) | |
html_options['href'] ||= url | |
if current_page?(url) | |
content_tag(:li, class: "active") do | |
content_tag(:a, name || url, html_options, &block) | |
end | |
else | |
content_tag(:li) do | |
content_tag(:a, name || url, html_options, &block) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment