ruby-on-railshamlcurrent-page

Ruby-on-Rails adding current_page? to my link_to


I'd like to add a

current_page?

to my

.navbar.navbar-default.admin-header
  %ul.nav.navbar-nav.navbar-left
   %li= link_to "Dashboard", admins_dashboard_path, class: 'active'

to achieve that if my current page is /dashboard only in that case will be the

class: 'active'

in my link (later i want to use specific stylesheet to active and not active nav links.

Please helap me to get this together! Thy


Solution

  • Documentation of this method describes how to implement it. In your case it's going to be something like:

    .navbar.navbar-default.admin-header
      %ul.nav.navbar-nav.navbar-left
       %li= link_to "Dashboard", admins_dashboard_path, class: ('active' if current_page?(admins_dashboard_path))