【问题标题】:Multi level menu, active links css highlight. (Ruby on Rails)多级菜单,活动链接 css 突出显示。 (Ruby on Rails)
【发布时间】:2010-05-09 15:35:04
【问题描述】:

网站结构:

/
/products
/products/design
/products/photo
/about

我想看到 当孩子处于活动状态时,父菜单项也被 CSS 突出显示。

(当“设计”或“照片”处于活动状态时,“产品”也应突出显示。)

我将它用于子网址和简单网址:

<li class="<%= current_page?(:action => 'design') %>">
    <%= link_to_unless_current 'Design', :design %>
</li>

对于“产品”的检查应该是这样的:

<%= current_page?(:action => 'products') ||
current_page?(:action => 'design') %> ||
current_page?(:action => 'photo') %>

但是三倍||不对,而且变复杂了。

我看到了一个帮手,就像这个:

def current(childs)
  if current_page?(:action => childs) 
  @container = "active"
  else
  @container = "inactive"
  end
end

使用者:&lt;%= current(:photo) %&gt;

那么,如何将我对“产品”、“设计”、“照片”的所有 3 项检查放在一个助手中?

并且可以使用 &lt;%= current(:products, :design, :photo) %&gt; 之类的东西

【问题讨论】:

    标签: ruby-on-rails css menu helper


    【解决方案1】:

    我不会重新创建轮子并使用像simple-navigation 这样的Rails menu-builder gem/plugin。

    这是demo of navigation and styling.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-27
      • 2013-01-20
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      相关资源
      最近更新 更多