Created
March 26, 2018 17:37
-
-
Save joshmosh/cc9f066e59eb2ea7662db4332ad1a62d to your computer and use it in GitHub Desktop.
Rails Active Link Helper
This file contains hidden or 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
module ApplicationHelper | |
def app_link_to(name, url, html_options, active_options) | |
css_class = html_options[:class].split(' ') | |
if params[:controller] == active_options[:controller] | |
css_class << active_options[:active_class] | |
end | |
html_options[:class] = css_class.join(' ') | |
link_to(name, url, html_options) | |
end | |
end |
This file contains hidden or 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
<%= app_link_to 'Clients', | |
clients_path, | |
{ class: 'navigation__app--link' }, | |
controller: 'clients', | |
active_class: 'selected' | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple example of how to extend the build in
link_to
helper to highlight links in your application. This is not intended to be a drop in solution for every case but it's a good place to start.