0

网站结构:

/
/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

由以下人员使用:<%= current(:photo) %>

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

并可以使用类似的东西<%= current(:products, :design, :photo) %>

4

1 回答 1

1

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

这是导航和样式的演示。

于 2010-05-09T19:04:06.507 回答