Best way to add “current” class to nav in Rails 3

后端 未结 24 1803
天涯浪人
天涯浪人 2020-11-29 15:05

I have some static pages in a navigation menu. I want to add a class like \"current\" to the item which is currently displaying.

The way I am doing so is to add tons

24条回答
  •  感动是毒
    2020-11-29 15:30

    I use a simple helper like this for top level links so the /stories/my-story page highlights the /stories link

    def nav_link text, url
    
      active = (url == request.fullpath || (url != '/' && request.fullpath[0..(url.size-1)] == url))
    
      "#{text}
  • ".html_safe end

提交回复
热议问题