【发布时间】: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
使用者:<%= current(:photo) %>
那么,如何将我对“产品”、“设计”、“照片”的所有 3 项检查放在一个助手中?
并且可以使用 <%= current(:products, :design, :photo) %> 之类的东西
【问题讨论】:
标签: ruby-on-rails css menu helper