简体   繁体   English

Ruby on Rails添加current_page吗? 到我的link_to

[英]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 要实现这一点,如果我的当前页面是/ dashboard,则只有在这种情况下

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 y

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM