Skip to content

Instantly share code, notes, and snippets.

@leylaKapi
Created February 27, 2017 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leylaKapi/56d67c3975efceadbdb16f9ad8d7f5bb to your computer and use it in GitHub Desktop.
Save leylaKapi/56d67c3975efceadbdb16f9ad8d7f5bb to your computer and use it in GitHub Desktop.
Navbar active class in rails
%nav.menu
.logo
= link_to path do
= image_tag 'logo-index.png', class: 'logo-img'
%ul.main-menu
%li.menu-item{class: "#{set_active_class 'welcome'}"}
= link_to root_path, data: {no_turbolink: false} do
%i.fa.fa-home
= t('navbar.home_page')
%li.menu-item{class: "#{set_active_class 'editor_payment'}"}
= link_to editor_payment_index_path do
%i.fa.fa-magnet
= t('navbar.design')
// set active class from controller name
def set_active_class value
if params[:controller] == value
'active'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment