【问题标题】:Rails Bootstrap Navbar and refineryCMSRails Bootstrap 导航栏和炼油厂CMS
【发布时间】:2013-02-07 19:47:57
【问题描述】:

有没有人在refineryCMS 中实现过Rails Bootstrap Navbar?

我很难弄清楚如何呈现下拉菜单。

这应该是实现此目的的正确方法?

_menu.html.erb

<%    
  if (roots = local_assigns[:roots] || (collection ||= refinery_menu_pages).roots).present?
    dom_id ||= 'menu'
  css = [(css || 'menu'), 'clearfix'].flatten.join(' ')
    hide_children = Refinery::Core.menu_hide_children if hide_children.nil?
-%>
<div class="navbar">
  <div class="navbar-inner">
    <div class="container">

      <nav id='<%= dom_id %>' class='<%= css %> nav'>
        <ul class="nav">


          <%= render :partial => '/refinery/menu_branch', :collection => roots,
                     :locals => {
                       :hide_children => hide_children,
                       :sibling_count => (roots.length - 1),
                       :menu_levels => local_assigns[:menu_levels],
                       :apply_css => true #if you don't care about class='first' class='last' or class='selected' set apply_css to false for speed.
                     } -%>

        </ul>
        </nav>
    </div>
    </div>
</div>
<% end -%>

_menu_branch.html.erb

<%
  if !!local_assigns[:apply_css] and (classes = custom_menu_branch_css(local_assigns)).any?
    css = "class='#{classes.join(' ')}'".html_safe
  end

-%>
<li class="dropdown">
<% if menu_branch.children.present? &&  menu_branch.ancestors.length < 1 %>
<%= link_to(menu_branch.title, refinery.url_for(menu_branch.url), class: "dropdown-togle", data: { toggle: "dropdown" }) -%>
<% else %>
<%= link_to(menu_branch.title, refinery.url_for(menu_branch.url)) -%>
<% end %>
  <% if ( (children = menu_branch.children unless hide_children).present? &&
          (!local_assigns[:menu_levels] || menu_branch.ancestors.length < local_assigns[:menu_levels]) ) -%>


      <ul class="dropdown-menu">
      <%= render :partial => '/refinery/menu_branch', :collection => children,
                 :locals => {
                   :apply_css => local_assigns[:apply_css],
                   :hide_children => !!hide_children,
                   :menu_levels => local_assigns[:menu_levels]
                  } -%>

    </ul>
</li>
<% end -%>

nav_bar sn-p

<%= nav_bar :fixed => :top, :brand => "Fashionable Clicheizr 2.0", :responsive => true do %>
    <%= menu_group do %>
        <%= menu_item "Home", root_path %>
        <%= menu_divider %>
        <%= drop_down "Products" do %>
            <%= menu_item "Things you can't afford", expensive_products_path %>
            <%= menu_item "Things that won't suit you anyway", harem_pants_path %>
            <%= menu_item "Things you're not even cool enough to buy anyway", hipster_products_path %>
            <% if current_user.lives_in_hackney? %>
                <%= menu_item "Bikes", fixed_wheel_bikes_path %>
            <% end %>
        <% end %>
        <%= menu_item "About Us", about_us_path %>
        <%= menu_item "Contact", contact_path %>
    <% end %>
    <%= menu_group :pull => :right do %>
        <% if current_user %>
            <%= menu_item "Log Out", log_out_path %>
        <% else %>
            <%= form_for @user, :url => session_path(:user), html => {:class=> "navbar-form pull-right"} do |f| -%>
              <p><%= f.text_field :email %></p>
              <p><%= f.password_field :password %></p>
              <p><%= f.submit "Sign in" %></p>
            <% end -%>
        <% end %>
    <% end %>
<% end %>

【问题讨论】:

    标签: ruby-on-rails-3 refinerycms


    【解决方案1】:

    面对同样的问题几个小时。 有更漂亮的代码(或者更接近炼油厂标准)的解决方案,我相信,最好覆盖基础炼油厂 menu_presenter 首先看一下类似的任务http://refinerycms.com/guides/menu-presenter 和这个:http://refinerycms.com/guides/extending-controllers-with-decorators

    所以。基于那篇文章让我们这样做

    app/decorators/models/refinery/page_decorator.rb:

    Refinery::Page.class_eval do
      def self.menu_pages
        where :show_in_menu => true
      end
    end
    

    app/helpers/application_helper.rb

    module ApplicationHelper
      def menu_header
        menu_items = Refinery::Menu.new(Refinery::Page.menu_pages)
    
        presenter = Refinery::Pages::MenuPresenter.new(menu_items, self)
        presenter.first_css = nil
        presenter.last_css = nil
    
        presenter
      end
    end
    

    在终端运行中:

    cd /path/to/app/
    rake refinery:override presenter=refinery/pages/menu_presenter
    

    它将生成 app/presenters/refinery/pages/menu_presenter.rb 将其更改为:

    require 'active_support/core_ext/string'
    require 'active_support/configurable'
    require 'action_view/helpers/tag_helper'
    require 'action_view/helpers/url_helper'
    
    module Refinery
      module Pages
        class MenuPresenter
          include ActionView::Helpers::TagHelper
          include ActionView::Helpers::UrlHelper
          include ActiveSupport::Configurable
    
          config_accessor :roots, :menu_tag, :list_tag, :list_item_tag, :css, :dom_id,
                          :max_depth, :selected_css, :first_css, :last_css, :list_first_css,
                          :list_dropdown_css, :list_item_dropdown_css,
                          :list_item__css, :link_dropdown_options, :carret
    
          self.dom_id = :div
          self.css = ["nav-collapse", "collapse", "navbar-responsive-collapse"]
          self.menu_tag = :nav
          self.list_tag = :ul
          self.list_first_css = :nav
          self.carret = '<b class="caret"></b>'
          self.list_dropdown_css = "dropdown-menu"
          self.link_dropdown_options = {class: "toggle-dropdown", data: {:toggle=>"dropdown"}}
          self.list_item_tag = :li
          self.list_item_dropdown_css = :dropdown
          self.list_item__css = nil
          self.selected_css = :active
          self.first_css = :first
          self.last_css = :last
          def roots
            config.roots.presence || collection.roots
          end
    
          attr_accessor :context, :collection
          delegate :output_buffer, :output_buffer=, :to => :context
    
          def initialize(collection, context)
            @collection = collection
            @context = context
          end
    
          def to_html
            render_menu(roots) if roots.present?
          end
    
          private
          def render_menu(items)
            content_tag(menu_tag, :id => dom_id, :class => css) do
              render_menu_items(items)
            end
          end
    
          def render_menu_items(menu_items)
            if menu_items.present?
              content_tag(list_tag, :class => menu_items_css(menu_items)) do
                menu_items.each_with_index.inject(ActiveSupport::SafeBuffer.new) do |buffer, (item, index)|
                  buffer << render_menu_item(item, index)
                end
              end
            end
          end
    
          def render_menu_item(menu_item, index)
            content_tag(list_item_tag, :class => menu_item_css(menu_item, index)) do
              @cont = context.refinery.url_for(menu_item.url)
              buffer = ActiveSupport::SafeBuffer.new
                if check_for_dropdown_item(menu_item)
                  buffer << link_to((menu_item.title+carret).html_safe, "#", link_dropdown_options)
                else
                  buffer << link_to(menu_item.title, context.refinery.url_for(menu_item.url))
                end
              buffer << render_menu_items(menu_item_children(menu_item))
              buffer
            end
          end
    
          def check_for_dropdown_item(menu_item)
            (menu_item!=roots.first)&&(menu_item_children(menu_item).count > 0)
          end
    
          # Determines whether any item underneath the supplied item is the current item according to rails.
          # Just calls selected_item? for each descendant of the supplied item
          # unless it first quickly determines that there are no descendants.
          def descendant_item_selected?(item)
            item.has_children? && item.descendants.any?(&method(:selected_item?))
          end
    
          def selected_item_or_descendant_item_selected?(item)
            selected_item?(item) || descendant_item_selected?(item)
          end
    
          # Determine whether the supplied item is the currently open item according to Refinery.
          def selected_item?(item)
            path = context.request.path
            path = path.force_encoding('utf-8') if path.respond_to?(:force_encoding)
    
            # Ensure we match the path without the locale, if present.
            if %r{^/#{::I18n.locale}/} === path
              path = path.split(%r{^/#{::I18n.locale}}).last.presence || "/"
            end
    
            # First try to match against a "menu match" value, if available.
            return true if item.try(:menu_match).present? && path =~ Regexp.new(item.menu_match)
    
            # Find the first url that is a string.
            url = [item.url]
            url << ['', item.url[:path]].compact.flatten.join('/') if item.url.respond_to?(:keys)
            url = url.last.match(%r{^/#{::I18n.locale.to_s}(/.*)}) ? $1 : url.detect{|u| u.is_a?(String)}
    
            # Now use all possible vectors to try to find a valid match
            [path, URI.decode(path)].include?(url) || path == "/#{item.original_id}"
          end
    
          def menu_items_css(menu_items)
            css = []
    
            css << list_first_css if (roots == menu_items)
            css << list_dropdown_css if (roots != menu_items)
    
            css.reject(&:blank?).presence
    
          end
    
          def menu_item_css(menu_item, index)
            css = []
    
            css << list_item_dropdown_css if (check_for_dropdown_item(menu_item))
            css << selected_css if selected_item_or_descendant_item_selected?(menu_item)
            css << first_css if index == 0
            css << last_css if index == menu_item.shown_siblings.length
    
            css.reject(&:blank?).presence
          end
    
          def menu_item_children(menu_item)
            within_max_depth?(menu_item) ? menu_item.children : []
          end
    
          def within_max_depth?(menu_item)
            !max_depth || menu_item.depth < max_depth
          end
    
        end
      end
    end
    

    几乎完成了。将 menu_header.to_html 添加到菜单容器内的菜单中,如下所示:

        <div class="navbar navbar-fixed-top">
          <div class="navbar-inner">
            <div class="container">
              <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </a>
              <a class="brand" href="#"><%=Refinery::Core::site_name %></a>
              <%= menu_header.to_html %>
            </div>
          </div>
        </div>
    

    PS:RefineryCMS 2.1.0

    【讨论】:

    • 我已经尝试过了——它几乎就在那里,除了一些小改动之外,我还没有彻底测试它(尽管下拉菜单似乎对我不起作用)。为了让 Bootstrap 菜单正确显示,我需要将上面 Presenter 代码中的 list_first_css 行更改为:self.list_first_css = "nav navbar-nav"。但是 +1 以获得全面的答案,这看起来会给我一个很好的起点。
    • ... menu_items_css 方法未定义... :-)
    • Valentine Konov 方法看起来不错,但在我的情况下,下拉菜单不起作用。
    • 你不需要覆盖整个MenuPresenter;只需将其子类化,覆盖您想要更改的方法并在模板中使用新的演示者。
    【解决方案2】:

    带有 Bootstrap 3 的炼油厂 2.1.0

    以上解决方案都不适合我。所以我不得不适应瓦伦丁科诺夫的回答。您可以在下面找到我的所有文件。如果您需要任何帮助,您可以随时给我留言。我们开始吧!

    1) 检查您的 RefineryCMS 和 Bootstrap 版本

    宝石文件

    gem 'bootstrap-sass', '~> 3.1.1'
    gem 'refinerycms', '~> 2.1.0'
    

    2) 保存几行代码

    一个。您实际上不需要创建 app/decorators/models/refinery/page_decorator.rb 文件。

    b.您也可以忘记 menu_header 方法。这样,您将拥有:

    app/helpers/application_helper.rb

    module ApplicationHelper
    end
    

    3) 现在让我们开始真正的工作

    一个。覆盖你的默认标题:

    $ rake refinery:override view=refinery/_header.html
    

    并将其代码更改为:

    app/views/refinery/_header.html.erb

    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
    
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#"><%=Refinery::Core::site_name %></a>
            </div>
    
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <%= Refinery::Pages::MenuPresenter.new(refinery_menu_pages, self).to_html %>
            </div>
        </div>
    </nav>
    

    b.现在转到终端并运行rake refinery:override presenter=refinery/pages/menu_presenter。它将生成一个 menu_presenter.rb 文件。改成这样:

    app/presenters/refinery/pages/menu_presenter.rb

    require 'active_support/core_ext/string'
    require 'active_support/configurable'
    require 'action_view/helpers/tag_helper'
    require 'action_view/helpers/url_helper'
    
    module Refinery
        module Pages
            class MenuPresenter
                include ActionView::Helpers::TagHelper
                include ActionView::Helpers::UrlHelper
                include ActiveSupport::Configurable
    
                config_accessor :roots, :menu_tag, :list_tag, :list_item_tag, :css, :dom_id,
                                                :max_depth, :selected_css, :first_css, :last_css, :list_first_css,
                                                :list_dropdown_css, :list_item_dropdown_css,
                                                :list_item__css, :link_dropdown_options, :carret
    
                # self.dom_id = nil
                # self.css = "pull-left"
                self.menu_tag = :section
                self.list_tag = :ul
                self.list_first_css = ["nav", "navbar-nav", "navbar-right"]
                self.carret = '<b class="caret"></b>'
                self.list_dropdown_css = "dropdown-menu"
                self.link_dropdown_options = {class: "dropdown-toggle", data: {:toggle=>"dropdown"}}
                self.list_item_tag = :li
                self.list_item_dropdown_css = :dropdown
                self.list_item__css = nil
                self.selected_css = :active
                self.first_css = :first
                self.last_css = :last
    
                def roots
                    config.roots.presence || collection.roots
                end
    
                attr_accessor :context, :collection
                delegate :output_buffer, :output_buffer=, :to => :context
    
                def initialize(collection, context)
                    @collection = collection
                    @context = context
                end
    
                def to_html
                    render_menu(roots) if roots.present?
                end
    
                private
                def render_menu(items)
                    content_tag(menu_tag, :id => dom_id, :class => css) do
                        render_menu_items(items)
                    end
                end
    
                def render_menu_items(menu_items)
                    if menu_items.present?
                        content_tag(list_tag, :class => menu_items_css(menu_items)) do
                            menu_items.each_with_index.inject(ActiveSupport::SafeBuffer.new) do |buffer, (item, index)|
                                buffer << render_menu_item(item, index)
                            end
                        end
                    end
                end
    
                def render_menu_item(menu_item, index)
                    content_tag(list_item_tag, :class => menu_item_css(menu_item, index)) do
                        @cont = context.refinery.url_for(menu_item.url)
                        buffer = ActiveSupport::SafeBuffer.new
                            if check_for_dropdown_item(menu_item)
                                buffer << link_to((menu_item.title+carret).html_safe, "#", link_dropdown_options)
                            else
                                buffer << link_to(menu_item.title, context.refinery.url_for(menu_item.url))
                            end
                        buffer << render_menu_items(menu_item_children(menu_item))
                        buffer
                    end
                end
    
                def check_for_dropdown_item(menu_item)
                    (menu_item!=roots.first)&&(menu_item_children(menu_item).count > 0)
                end
    
                # Determines whether any item underneath the supplied item is the current item according to rails.
                # Just calls selected_item? for each descendant of the supplied item
                # unless it first quickly determines that there are no descendants.
                def descendant_item_selected?(item)
                    item.has_children? && item.descendants.any?(&method(:selected_item?))
                end
    
                def selected_item_or_descendant_item_selected?(item)
                    selected_item?(item) || descendant_item_selected?(item)
                end
    
                # Determine whether the supplied item is the currently open item according to Refinery.
                def selected_item?(item)
                    path = context.request.path
                    path = path.force_encoding('utf-8') if path.respond_to?(:force_encoding)
    
                    # Ensure we match the path without the locale, if present.
                    if %r{^/#{::I18n.locale}/} === path
                        path = path.split(%r{^/#{::I18n.locale}}).last.presence || "/"
                    end
    
                    # First try to match against a "menu match" value, if available.
                    return true if item.try(:menu_match).present? && path =~ Regexp.new(item.menu_match)
    
                    # Find the first url that is a string.
                    url = [item.url]
                    url << ['', item.url[:path]].compact.flatten.join('/') if item.url.respond_to?(:keys)
                    url = url.last.match(%r{^/#{::I18n.locale.to_s}(/.*)}) ? $1 : url.detect{|u| u.is_a?(String)}
    
                    # Now use all possible vectors to try to find a valid match
                    [path, URI.decode(path)].include?(url) || path == "/#{item.original_id}"
                end
    
                def menu_items_css(menu_items)
                    css = []
    
                    css << list_first_css if (roots == menu_items)
                    css << list_dropdown_css if (roots != menu_items)
    
                    css.reject(&:blank?).presence
    
                end
    
                def menu_item_css(menu_item, index)
                    css = []
    
                    css << list_item_dropdown_css if (check_for_dropdown_item(menu_item))
                    css << selected_css if selected_item_or_descendant_item_selected?(menu_item)
                    css << first_css if index == 0
                    css << last_css if index == menu_item.shown_siblings.length
    
                    css.reject(&:blank?).presence
                end
    
                def menu_item_children(menu_item)
                    within_max_depth?(menu_item) ? menu_item.children : []
                end
    
                def within_max_depth?(menu_item)
                    !max_depth || menu_item.depth < max_depth
                end
    
            end
        end
    end
    

    c。重新启动服务器并查看结果。如果您已经创建了一些页面,您的导航栏应该类似于下图:

    【讨论】:

    • 你的意思是 $ rake refinery:override view=refinery/_header.html
    • 哇,你救了我的命!为了让它与我的网页设计师的代码一起使用,我只需要更改开头附近的内容:# self.menu_tag = :section self.menu_tag = :div self.css = "navbar-collapse collapse navbar-right" self.list_tag = :ul self.list_first_css = ["nav", "navbar-nav"]` (使用您建议的代码,有一个双 navbar-right 类,菜单中间还有一个额外部分)
    【解决方案3】:

    试试这个 _menu_branch.html.erb

    <% if ( (children = menu_branch.children unless hide_children).present? &&
            (!local_assigns[:menu_levels] || menu_branch.ancestors.length < local_assigns[:menu_levels]) ) -%>
    
    <%
      if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
        css = "class='#{classes.join(' ')} dropdown'".html_safe
      end
    
    -%>
    <li<%= ['', css].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
    <%= link_to("#{menu_branch.title} <b class='caret'></b>".html_safe, refinery.url_for(menu_branch.url), :class=>"dropdown-toggle", 'data-toggle'=>'dropdown') -%>
        <ul class='dropdown-menu'>
          <%= render :partial => '/refinery/menu_branch', :collection => children,
                     :locals => {
                       :apply_css => local_assigns[:apply_css],
                       :hide_children => !!hide_children,
                       :menu_levels => local_assigns[:menu_levels]
                     } -%>
        </ul>
    
    </li>
    <% else -%>
    <%
      if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
        css = "class='#{classes.join(' ')}'".html_safe
      end
    
    -%>
    <li<%= ['', css].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
    <%= link_to(menu_branch.title, refinery.url_for(menu_branch.url)) -%>
    </li>
    <% end -%>
    

    _menu.html.erb

    <%
      # Collect the root items.
      # ::Refinery::Menu is smart enough to remember all of the items in the original collection.
      if (roots = local_assigns[:roots] || (collection ||= refinery_menu_pages).roots).present?
        dom_id ||= 'menu'
        css = [(css || 'menu clearfix')].flatten.join(' ')
        hide_children = Refinery::Core.menu_hide_children if hide_children.nil?
    -%>
    <div id="main-menu" class="nav-collapse">
      <nav id='<%= dom_id %>' class='<%= css %>'>
        <ul id="main-menu-left" class="nav">
          <%= render :partial => '/refinery/menu_branch', :collection => roots,
                     :locals => {
                       :hide_children => hide_children,
                       :sibling_count => (roots.length - 1),
                       :menu_levels => local_assigns[:menu_levels],
                       :apply_css => true #if you don't care about class='first' class='last' or class='selected' set apply_css to false for speed.
                     } -%>
        </ul>
      </nav>
    </div>
    <% end -%>
    

    和_header.html.erb

    <div class="container">
        <div class="navbar">
          <div class="navbar-inner">
            <div class="container">
              <a data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar">
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                    </a>
        <%= link_to Refinery::Core.site_name, refinery.root_path, :class => "brand" %>
    
        <%= render(:partial => "/refinery/menu", :locals => {
                     :dom_id => 'menu',
                     :css => 'menu'
                   }) %>
            </div>
          </div>
        </div>  
    </div>
    

    【讨论】:

    • RefineryCMS 刚刚更新到 2.1,不幸的是,无论如何,对于这篇文章,他们已经更改并替换了上面列出的菜单系统。当然,它不会在一夜之间消失,但​​我只是想我会提到这一点,以防您考虑在不久的将来更新到 RefineryCMS 2.1。他们已经开始使用 Menu Presenter 来完成 CMS 菜单的呈现。我意识到我的姿势在这里不会有太大帮助,但这是新的菜单系统指南。 refinerycms.com/guides/menu-presenter
    【解决方案4】:

    user1852788 概述的方法对我有用。如果您使用带有下拉菜单的菜单,请不要忘记在 application.js 清单文件中加载引导 js:

    //= require jquery
    //= require jquery_ujs
    //= require bootstrap
    //= require_tree .
    

    然后调用下拉函数(我有一个叫layout.js.coffee的文件):

    $('.dropdown-toggle').dropdown()
    

    【讨论】:

      【解决方案5】:

      这个要点对我来说非常适合最新的炼油厂和引导程序https://gist.github.com/npflood/2d3f5fc44518ef231195

      【讨论】:

        【解决方案6】:

        有一个 gem 试图解决这个问题。

        https://github.com/ghoppe/refinerycms-bootstrap

        但我个人一直遇到问题。

        【讨论】:

          【解决方案7】:

          我找到了更简单的方法来为 reinerycms 2-0-stable 执行此操作

          我的解决方案如下:

          首先 _menu.html.erb 使用引导类更新 css 变量并添加必要的 html,例如我添加了 div 以包装 ul

          <%
            # Collect the root items.
            # ::Refinery::Menu is smart enough to remember all of the items in the original collection.
            if (roots = local_assigns[:roots] || (collection ||= refinery_menu_pages).roots).present?
              dom_id ||= 'menu'
              css = [(css || 'pull-right')].flatten.join(' ')
              hide_children = Refinery::Core.menu_hide_children if hide_children.nil?
          -%>
          <nav id='<%= dom_id %>' class='<%= css %>'>
            <div class="collapse navbar-collapse">
              <ul class="nav nav-pills navbar-nav">
                <%= render :partial => '/refinery/menu_branch', :collection => roots,
                           :locals => {
                             :hide_children => hide_children,
                             :sibling_count => (roots.length - 1),
                             :menu_levels => local_assigns[:menu_levels],
                             :apply_css => true #if you don't care about class='first' class='last' or class='selected' set apply_css to false for speed.
                           } -%>
              </ul>
            </div>
          </nav>
          <% end -%>
          

          第二个 _menu_branch.html.erb 使用引导类更新类

              <%
            if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
              css = "class='#{classes.join(' ')}'".html_safe
            end
          -%>
          <% if ( (children = menu_branch.children unless hide_children).present? &&
                  (!local_assigns[:menu_levels] || menu_branch.ancestors.length < local_assigns[:menu_levels]) ) -%>
            <li class="dropdown">
              <a href="<%= refinery.url_for(menu_branch.url) %>" class="dropdown-toggle" data-toggle="dropdown"><%= menu_branch.title %><b class="caret"></b></a>
              <ul class='dropdown-menu'>
                <%= render :partial => '/refinery/menu_branch', :collection => children,
                           :locals => {
                             :apply_css => local_assigns[:apply_css],
                             :hide_children => !!hide_children,
                             :menu_levels => local_assigns[:menu_levels]
                           } -%>
              </ul>
          <% else -%>
            <li<%= ['', css].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
            <%= link_to(menu_branch.title, refinery.url_for(menu_branch.url)) -%>
          <% end -%>
            </li>
          

          现在您的菜单应该可以正常显示了。要启用Active,您只需要通过更改以下代码来更新/config/initializers/refinery/core.rb 文件:

          将选中的更改为active

              # CSS class selectors for menu helper
            config.menu_css = {:selected=>"active", :first=>"first", :last=>"last"}
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-05-09
            • 1970-01-01
            • 2015-11-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多