作者:雯颜哥_135 | 2023-08-29 23:06
现在我的导航部分看起来像这样(x10按钮)......
<% if current_controller == "territories" %>
<%= link_to "Territories", {:controller => 'territories'}, :class => 'active' %>
<% else %>
<%= link_to "Territories", {:controller => 'territories'} %>
<% end %>
<% if current_controller == "contacts" %>
<%= link_to "Contacts", {:controller => 'Contacts'}, :class => 'active' %>
<% else %>
<%= link_to "Contacts", {:controller => 'Contacts'} %>
<% end %>
这样做有更优雅/干燥的解决方案吗?
1> kch..:
与Chuck所说的类似:
<% TARGETS.each do |target| %>
<%= link_to target.humanize,
{ :controller => target },
class => ('active' if current_controller == target)) %>
<% end %>