Answer the question
In order to leave comments, you need to log in
How to properly highlight the current menu item in the site navigation?
Are there generally accepted techniques/gems for highlighting the current menu item?
Something looks ugly to me ... It turns out garbage:
%ul.side-nav
- curclass = controller_name=="accounts" ? "sub-active" : ""
- curclass = "active" if controller_name=="groups" || controller_name=="seasons"
%li{class: curclass}
= link_to admin_accounts_path do
Люди
- if controller_name=="accounts"
%i.material-icons label_outline
%ul
- subcurclass = "sub-active" if controller_name=="groups"
%li.child{class: subcurclass}
= link_to admin_groups_path do
Группы
- if controller_name=="groups"
%i.material-icons label_outline
%ul
- subcurclass = controller_name=="seasons" ? 'sub-active' : ''
%li.child{class: subcurclass}
= link_to admin_seasons_path do
Сезоны
- if controller_name=="seasons"
%i.material-icons label_outline
Answer the question
In order to leave comments, you need to log in
Just create a helper. Example:
def nav_link(link_text, link_path)
class_name = current_page?(link_path) ? 'current' : ''
content_tag(:li, :class => class_name) do
link_to link_text, link_path
end
end
nav_link 'Home', root_path
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question