开发者

User Helper Method for Current Navigation in Rails 3

I have the following navigation HTML:

<nav class="col9">
      <ul>
        <li class="current"><a href="/">Home</a></li>
        <li><a href="/">About</a></li>
        <li><a href="/">Apps</a></li>
        <li><a href="/">Blog</a></li>
        <li><a href="/"开发者_开发百科>Contact</a></li>
      </ul>
</nav>

I need to find a way to dynamically add the class of "current" to the relevant list item (if we are on the page).

I have the following code in my application_helper.rb:

def menu_link(name, options = {}, html_options = {})
        html_options.merge!({ :class => 'current'}) if current_page?(options)
        link_to name, options, html_options
    end

However, this adds the class of current to the anchor tag instead of the list item. Would anyone be able to assist me in modifying this?

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜