使用Rails制作水平的导航菜单

Memu帮助类:

#encoding: utf-8
module MenuHelper
  def topmenu
     pages = {
        "pages" => { :name => '首页', :link => root_path},
        "recent" => { :name => '最新', :link => recent_path },
        "hot" => { :name => '热门', :link => hot_path },
        "class" => { :name => '分类', :link => class_path }
     }

    pages.map do |key, value|
      classnames = ' class=current-menu-item' if controller.controller_name == key
      "<li#{classnames}>#{link_to(value[:name], value[:link])}</li>"
    end
  end
end

View前端脚本 来至 lehazi.com Q群193737895

<ul>
          <%= raw topmenu.join %>
        </ul>

相关推荐