0

我有一个下拉菜单,当页面使用 current_page 时它会处于活动状态?像这样的方法:

<ul>
<li class="dropdown">
  <a href="javascript:void(0)" class="dropdown-toggle <%= current_page?(company_dropA_path(@company)) || current_page?(company_dropB_path(@company)) || current_page?(company_dropC_path(@company)) || current_page?(company_dropD_path(@company)) ? 'active' : '' %>" data-toggle="dropdown"><%= @company.name %> <b class="caret"></b></a>
    <ul class="dropdown-menu">
       <li><%= link_to 'Dropdown A', company_dropA_path(@company) %></li>
       <li><%= link_to 'Dropdown B', company_dropB_path(@company) %></li>
       <li><%= link_to 'Dropdown C', company_dropC_path(@company) %></li>
       <li><%= link_to 'Dropdown D', company_dropD_path(@company) %></li>
    </ul>
</li>
</ul>

正如您可能注意到的,current_page 变得非常长且凌乱。我怎样才能将其转换为助手?

4

1 回答 1

1
%w[A B C D].any?{|c| current_page?(send("company_drop#{c}_path", @company))}
于 2014-03-12T21:30:49.370 回答