我是 Rails 的新手:我的侧边导航部分会执行每一步,并为其提供一个图标和一个链接。我希望当前活动步骤在顶部导航中具有与侧面导航相同的图标。但是,<%= icon[i] %> 将不起作用,因为 [i] 来自不同视图中的不同块。我将如何使活动链接顶部的导航具有与侧面导航相同的图标 [i] 而无法访问 i?见下文。
_side_navigation.html.erb
<% icon= ["icon-link", "icon-bar-chart", "icon-edit", "icon-beaker","icon-link", "icon-bar-chart", "icon-edit", "icon-beaker"] %>
<% @step_list.each_with_index do |step, i| %>
<% case step.media_type %>
<% when 'video' %>
<li class="<%= nav_active step %>">
<a href = "
<i class='icon-info-sign icon-2x'></i>
<span>Video</span>
</a>
</li>
<% when 'excel' %>
<li class="<%= nav_active step %>">
<i class="<%= icon[i] %> icon-2x"></i> **<<I need this [i] in the other partial so I know which element of the array is chosen**
<span>Step <%= i %> </span>
</a>
</li>
<% else %>
<li class="<%= nav_active step %>">
<i class="<%= icon[i] %> icon-2x"></i>
<span>Step <%= i %></span>
</a>
</li>
<% end %>
<% end %>
_top_navigation.html.erb
<div class="area-top clearfix">
<div class="pull-left header">
<% case @step.media_type %>
<% when 'video' %>
<h3 class="title">
<i class="<%= icon[i] %>"></i></i> <<<here is the problem since, it does not have access to the current "i" from the other block
Video
</h3>
<h5>
A video for the course is here
</h5>
<% when 'excel' %>
<h3 class="title">
<i class="<%= icon[i] %>"></i></i>
Excel
</h3>
<h5>
Please use the excel sheet below to complete the challenge.
</h5>
<% else %>
<h3 class="title">
<i class="<%= icon[i] %>"></i></i>
Multiple Choice
</h3>
<h5>
Please choose from a selection below
</h5>
<% end %>
</div>