Last active
February 3, 2017 13:31
-
-
Save spencerldixon/6c368aab02c1a3a81b23fea70b0b616d to your computer and use it in GitHub Desktop.
Various Active Link Helpers for Rails views
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
# Bootstrap 4 (wraps in an li and applys the active class to the li) | |
def active_link_to(name, path) | |
active_class = "active" if current_page?(path) | |
content_tag(:li, class: "nav-item #{active_class}") do | |
link_to(name, path, class: "nav-link") | |
end | |
end | |
# Anything else | |
def active_link_to(name, path) | |
active_class = "active" if current_page?(path) | |
link_to(name, path, class: "other_classes #{active}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment